<template>
  <div class="app-container calendar-list-container">
    <!-- filter 条件查询 -->
    <div class="filter-container">
      <el-form label-width="100px" inline label-position="left">
        <el-input
          clearable
          type="number"
          @keyup.enter.native="handleFilter"
          v-model="listQuery.equipmentId"
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          class="filter-item"
          maxlength="20"
          placeholder="请输入设备Id"
        />
        <el-input
          clearable
          @keyup.enter.native="handleFilter"
          v-model="listQuery.equipmentNumber"
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          class="filter-item"
          maxlength="20"
          placeholder="请输入设备编号"
        />
        <el-input
          clearable
          @keyup.enter.native="handleFilter"
          v-model="listQuery.deviceId"
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          class="filter-item"
          maxlength="20"
          placeholder="请输入deviceId"
        />
        <el-input
          clearable
          @keyup.enter.native="handleFilter"
          v-model="listQuery.authInfo"
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          class="filter-item"
          maxlength="20"
          placeholder="请输入鉴权信息"
        />
        <el-select
          v-model="listQuery.equipmentType"
          filterable
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          class="filter-item"
          placeholder="请选择设备类型"
        >
          <el-option
            v-for="item in equipmentTypeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>

        <el-select
          v-model="listQuery.equipmentStatus"
          filterable
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          class="filter-item"
          placeholder="请选择设备状态"
        >
          <el-option
            v-for="item in equipmentStatusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>

        <el-input
          clearable
          @keyup.enter.native="handleFilter"
          v-model="listQuery.address"
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          class="filter-item"
          maxlength="20"
          placeholder="地址"
        />
        <el-input
          clearable
          @keyup.enter.native="handleFilter"
          v-model="listQuery.userName"
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          class="filter-item"
          maxlength="20"
          placeholder="请输入代理商姓名"
        />

        <el-select
          v-model="listQuery.isFlag"
          filterable
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          class="filter-item"
          placeholder="请选择状态"
        >
          <el-option
            v-for="item in isFlagOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>

        <!-- 2022.09.07  合并为时间日期选择器 -->
        <el-date-picker
          v-model="dateTime"
          type="datetimerange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:00"
          @change="getDateTime"
        >
        </el-date-picker>

        <!-- <el-date-picker
          v-model="listQuery.startTime"
          type="datetime"
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择开始日期"
          align="center"
        ></el-date-picker>
        <el-date-picker
          v-model="listQuery.endTime"
          type="datetime"
          style="width: 200px; margin-right: 15px; margin-top: 7px"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择结束日期"
          align="center"
        ></el-date-picker> -->
      </el-form>
      <el-button
        class="filter-item"
        style="margin-top: 10px; margin-right: 15px"
        type="primary"
        v-waves
        icon="el-icon-search"
        @click="handleFilter"
        >搜索</el-button
      >

      <el-button
        class="filter-item"
        style="margin-top: 10px; margin-right: 15px"
        icon="el-icon-circle-plus-outline"
        v-waves
        @click="beforOpenDialog(1)"
        type="primary"
        >新增</el-button
      >
      <el-button
        class="filter-item"
        type="primary"
        style="margin-top: 10px; margin-right: 15px"
        @click="selectionShow(1)"
        >批量设置设备套餐</el-button
      >
      <el-button
        class="filter-item"
        type="primary"
        style="margin-top: 10px; margin-right: 15px"
        @click="selectionShow(2)"
        >批量设置设备卡套餐</el-button
      >
      <el-button
        class="filter-item"
        style="margin-top: 10px; margin-right: 15px"
        type="primary"
        @click="handleDownload"
        icon="el-icon-download"
        :loading="downloadLoading"
        >导出</el-button
      >
      <a
        href="https://www.golwayhhln.top/backJava/back/equipment/downLoadExcel?fileName=管理员-新增设备模板"
      >
        <el-button
          class="filter-item"
          style="margin-top: 10px; margin-right: 15px"
          type="primary"
          icon="el-icon-download"
          :loading="exlDownloadLoading"
          >下载模板</el-button
        >
      </a>

      <i style="overflow: hidden; position: absolute">
        <input
          id="up"
          ref="file"
          type="file"
          class="file-btn"
          @change="importEquipments"
          style="
            position: absolute;
            z-index: 100;
            margin-left: -180px;
            font-size: 60px;
            opacity: 0;
            filter: alpha(opacity=0);
            margin-top: -5px;
          "
        />
        <el-button
          type="primary"
          icon="el-icon-upload2"
          :loading="updataLoading"
          class="filter-item"
          style="margin-top: 10px; margin-right: 15px"
          >{{ updataTip }}</el-button
        >
      </i>
    </div>

    <div style="margin: 10px 0" v-if="selectionView">
      <el-button
        @click="selectionView = false"
        class="filter-item"
        style="margin-top: 10px; margin-right: 15px"
        type="primary"
        >取消批量新增套餐</el-button
      >

      <el-button
        class="filter-item"
        style="margin-top: 10px; margin-right: 15px"
        type="primary"
        @click="getEquipmentIds"
        >确定批量选择</el-button
      >
    </div>

    <!-- table 表格 -->
    <el-table
      :data="list"
      v-loading="loading.list"
      element-loading-text="给我一点时间"
      ref="multipleTable"
      border
      fit
      highlight-current-row
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        v-if="selectionView"
        width="30"
      ></el-table-column>
      <el-table-column label="序号" prop="index" align="center" width="60px" />
      <el-table-column label="设备Id" prop="equipmentId" align="center" />
      <el-table-column label="设备编号" prop="equipmentNumber" align="center" />
      <el-table-column label="deviceId" prop="deviceId" align="center" />
      <el-table-column label="鉴权信息" prop="authInfo" align="center" />

      <!-- <el-table-column
        label="设备类型"
        prop="equipmentTypeInfo"
        align="center"
      /> -->

      <el-table-column label="设备类型" align="center" prop="equipmentTypeInfo">
        <template slot-scope="scope" style="padding-left: 0px">
          <el-button
            :type="'text'"
            size="mini"
            :disabled="scope.row.equipmentType != 5"
            @click="
              getEquipmentOtherData(
                scope.row.equipmentId,
                scope.row.deviceId,
                scope.row.equipmentNumber,
                scope.row.equipmentType
              )
            "
            >{{ scope.row.equipmentTypeInfo }}
            <i class="el-icon-view el-icon--right"></i
          ></el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="设备状态"
        prop="equipmentStatusInfo"
        align="center"
      />
      <el-table-column label="喇叭状态" prop="trumpetInfo" align="center" />
      <el-table-column label="地址" prop="address" align="center" />
      <!-- 设备套餐 -->
      <el-table-column label="设备套餐" align="center" prop="isCashRequest">
        <template slot-scope="scope" style="padding-left: 0px">
          <el-button
            :type="scope.row.isCashRequest == 1 ? 'primary' : 'success'"
            size="mini"
            @click="mealView(scope.row.equipmentId)"
            >{{
              scope.row.isCashRequest == 1
                ? "查看"
                : scope.row.isCashRequest == 2
                ? "新增"
                : "-"
            }}</el-button
          >
        </template>
      </el-table-column>
      <!-- 设备卡套餐 -->
      <el-table-column
        label="设备卡套餐"
        align="center"
        prop="isCard"
        resizable
      >
        <template slot-scope="scope">
          <el-button
            :type="scope.row.isCard == 1 ? 'primary' : 'success'"
            size="mini"
            @click="
              EquipmentCardView(
                scope.row.isCard,
                scope.row.equipmentId,
                scope.row.equipmentNumber,
                scope.row.area,
                scope.row.city,
                scope.row.equipmentAddress
              )
            "
            >{{
              scope.row.isCard == 1
                ? "查看"
                : scope.row.isCard == 2
                ? "新增"
                : "-"
            }}</el-button
          >
        </template>
      </el-table-column>

      <!-- <el-table-column label="设备月用电量" align="center">
        <template slot-scope="scope">
          <router-link
            :to="{name:'equipment_equipmentEleDate', query: {equipmentId: scope.row.equipmentId}}">
            <el-button type="info">详情</el-button>
          </router-link>
        </template>
      </el-table-column>-->

      <!-- <el-table-column
        label="省级全资子公司"
        prop="coUserName"
        align="center"
      />-->
      <!-- <el-table-column label="物业" prop="esUserName" align="center" />  -->
      <el-table-column label="渠道商" prop="eqUserName" align="center" />

      <el-table-column
        label="设备月租(元)"
        prop="monthlyRentInfo"
        align="center"
      />
      <el-table-column label="代理商" prop="userName" align="center" />

      <el-table-column label="状态" prop="isFlagInfo" align="center" />
      <el-table-column label="火灾标志" prop="fireSign" align="center">
        <template slot-scope="scope">
          <div style="display: flex; justify-content: center">
            <div
              class="fireSign"
              :style="scope.row.fireSign == 1 ? 'backgroundColor:#f56c6c' : ''"
            >
              {{ scope.row.fireSign == 1 ? "" : "无火灾" }}
            </div>
          </div>

          <!-- <div v-if="scope.row.fireSign==0">
          无火灾
          </div>
          <div v-else  >
          <img style="height:50px;width:50px;border-radius:50%" src="../../assets/fire4.gif" alt="" >
          </div> -->
        </template>
      </el-table-column>
      <el-table-column label="创建时间" sortable prop="ctime" align="center" />
      <el-table-column label="操作" align="center" fixed="right" width="130">
        <template slot-scope="scope" style="width: 200px">
          <router-link
            :to="{
              name: 'equipmentDate',
              query: {
                equipmentId: scope.row.equipmentId,
                equipmentNumber: scope.row.equipmentNumber,
                equipmentType: scope.row.equipmentType,
              },
            }"
          >
            <el-button type="info">详情</el-button>
          </router-link>
          <el-button
            type="primary"
            size="mini"
            style="margin-top: 5px"
            @click="beforOpenDialog(2, scope.row)"
            >编辑</el-button
          >

          <el-button
            size="mini"
            style="margin-top: 5px"
            type="primary"
            v-if="scope.row.trumpet == 1"
            @click="updateTrumpet(scope.row.deviceId, `00`)"
            >打开喇叭</el-button
          >

          <el-button
            size="mini"
            style="margin-top: 5px"
            type="warning"
            v-else
            @click="updateTrumpet(scope.row.deviceId, `01`)"
            >关闭喇叭</el-button
          >
          <el-button
            size="mini"
            style="margin-top: 5px"
            type="primary"
            @click="getOneNetData(scope.row.deviceId)"
            >更新设备状态</el-button
          >
          <el-button
            size="mini"
            style="margin-top: 5px"
            type="info"
            @click="
              getEquipmentOtherData(
                scope.row.equipmentId,
                scope.row.deviceId,
                scope.row.equipmentNumber,
                scope.row.equipmentType
              )
            "
            >设备状态</el-button
          >

          <el-button
            size="mini"
            style="margin-top: 5px"
            type="primary"
            v-if="scope.row.isFlag == 2"
            @click="updateIsFlag(scope.row.equipmentId, scope.row.deviceId, 1)"
            >启用</el-button
          >

          <el-button
            size="mini"
            style="margin-top: 5px"
            type="warning"
            v-else
            @click="updateIsFlag(scope.row.equipmentId, scope.row.deviceId, 2)"
            >禁用</el-button
          >
          <el-button
            type="danger"
            size="mini"
            style="margin-top: 5px"
            :loading="loading.add"
            @click="detele(scope.row.equipmentId, scope.row.deviceId)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.offset"
        :page-sizes="[10, 20, 30, 40, 100, 300, 500]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>

    <el-dialog :title="diglogTitle" :visible.sync="dialog.add">
      <el-form
        :model="addQuery"
        :rules="bindRules"
        ref="bindForm"
        label-position="right"
        label-width="120px"
      >
        <el-form-item label="设备编码" prop="equipmentNumber">
          <el-input
            clearable
            :disabled="this.dialogType === 2"
            v-model="addQuery.equipmentNumber"
            maxlength="7"
            placeholder="请输入设备编号(长度为7，只能包含数字!如：2020年    2（充电设备类型） 0（设备生产年份） 00345（年度流水码） )"
          ></el-input>
        </el-form-item>
        <el-form-item label="deviceId" prop="deviceId">
          <el-input
            clearable
            :disabled="this.dialogType === 2"
            v-model="addQuery.deviceId"
            maxlength="512"
            placeholder="请输入deviceId"
          ></el-input>
        </el-form-item>
        <el-form-item label="设备类型" prop="equipmentType">
          <el-select
            :disabled="this.dialogType === 2"
            v-model="addQuery.equipmentType"
            placeholder="请选择设备类型"
            class="filter-item"
            style="width: 200px"
          >
            <el-option label="交流" :value="1"></el-option>
            <el-option label="交直流-单模块" :value="2"></el-option>
            <el-option label="交直流-双模块" :value="3"></el-option>
            <el-option label="充电柜" :value="5"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="所在地区" required>
          <el-form-item prop="province" style="display: inline-block">
            <el-select
              style="width: 100px"
              v-model="addQuery.province"
              placeholder="省"
              class="filter-item"
              @change="getCities2(1)"
            >
              <el-option
                v-for="p in provices"
                :label="p.NAME"
                :value="p.AREA_ID"
                :key="p.AREA_ID"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="city" style="display: inline-block">
            <el-select
              style="width: 100px"
              v-model="addQuery.city"
              placeholder="市"
              class="filter-item"
              @change="getAreas2(1)"
            >
              <el-option
                v-for="c in cities"
                :label="c.NAME"
                :value="c.AREA_ID"
                :key="c.AREA_ID"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="area" style="display: inline-block">
            <el-select
              style="width: 120px"
              v-model="addQuery.area"
              placeholder="区"
              class="filter-item"
            >
              <el-option
                v-for="a in areas"
                :label="a.NAME"
                :value="a.AREA_ID"
                :key="a.AREA_ID"
              />
            </el-select>
          </el-form-item>
        </el-form-item>
        <el-form-item label="详细地址" prop="equipmentAddress">
          <el-input
            type="textarea"
            :rows="3"
            v-model="addQuery.equipmentAddress"
            clearable
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="省级全资子公司" prop="companyId">
          <el-select
            style="width: 100%"
            v-model="addQuery.companyId"
            placeholder="请选择省级全资子公司"
            class="filter-item"
          >
            <el-option
              v-for="(item, index) in companyList"
              :label="item.userName"
              :value="item.agentId"
              :key="index"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item label="代理商" prop="managerId">
          <el-select
            style="width: 100%"
            v-model="addQuery.managerId"
            placeholder="请选择代理商"
            class="filter-item"
            @change="chooseAgent($event)"
          >
            <!-- <template v-for="item in agentList"  > -->
            <el-option
              v-for="item in agentList"
              :key="item.managerId"
              :label="item.userName"
              :value="item.managerId"
            >
            </el-option>
            <!-- </template> -->
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialog.add = false">取消</el-button>
        <el-button type="primary" :loading="loading.add" @click="add"
          >确定</el-button
        >
      </div>
    </el-dialog>
    <!--设置套餐信息  -->
    <el-dialog
      title="设置套餐信息"
      :visible.sync="dialog.create"
      @close="dialog.create = false"
    >
      <el-form
        :model="mealDetail"
        :rules="mealRules"
        ref="mealForm"
        label-position="right"
        label-width="200px"
      >
        <el-form-item label="充电收费类型" prop="chargeType">
          <el-select
            v-model="mealDetail.chargeType"
            placeholder="请选择收费类型"
            class="filter-item"
            style="width: 200px"
          >
            <el-option label="按次" :value="1"></el-option>
            <el-option label="按时间段" :value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="充电收费价格(元/次)"
          prop="chargeAmount"
          v-if="this.mealDetail.chargeType == 1"
        >
          <el-input
            clearable
            v-model="mealDetail.chargeAmount"
            maxlength="12"
            type="number"
            placeholder=" 请输入充电收费价格(元/次)"
          ></el-input>
        </el-form-item>

        <el-form-item label="收费标准" v-if="mealDetail.chargeType == 2">
          <el-row>
            <el-col
              :span="8"
              v-for="(item, index) in mealDetail.chargePowerData"
              :key="index"
            >
              <div class="powerSize">
                <div class="powerSizeTop">
                  <span>功率范围:</span>
                  {{ item.spower }}-{{ item.epower }}W
                </div>
                <div>
                  <div>
                    <span>峰值收费:</span>
                    {{ divide(item.chargePeakAmount,100) }}元
                  </div>
                  <div>
                    <span>低谷收费:</span>
                    {{ divide(item.chargeLowEbAmount,100) }}元
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-button
            type="primary"
            :loading="loading.create"
            @click="dialog.powerSetVisible = true"
            >重新设定</el-button
          >
        </el-form-item>
        <el-form-item
          label="电费收费时间间隔(分钟)"
          prop="amountTime"
          v-if="
            mealDetail.chargeType == 2 ||
            mealDetail.serviceType == 2 ||
            mealDetail.custodyType == 2
          "
        >
          <el-input
            clearable
            v-model="mealDetail.amountTime"
            maxlength="5"
            type="number"
            style="width: 200px"
            placeholder="请输入收费时间间隔(分钟)"
          ></el-input>
        </el-form-item>

        <el-form-item label="服务收费类型" prop="serviceType">
          <el-select
            v-model="mealDetail.serviceType"
            placeholder="请选择服务收费类型"
            class="filter-item"
            style="width: 200px"
          >
            <el-option label="免费" :value="0"></el-option>
            <el-option label="按次收费" :value="1"></el-option>
            <el-option label="按时间段收费" :value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="服务收费(元/次)"
          prop="serviceAmount"
          v-if="this.mealDetail.serviceType == 1"
        >
          <el-input
            clearable
            v-model="mealDetail.serviceAmount"
            maxlength="12"
            type="number"
            placeholder="请输入每次服务收费金额(元/次)"
          ></el-input>
        </el-form-item>

        <!-- <el-form-item
          label="峰值时间段服务收费(元/每个收费时间间隔)"
          prop="servicePeakAmount"
          v-if="this.mealDetail.serviceType === 2"
        >
          <el-input
            clearable
            v-model="mealDetail.servicePeakAmount"
            maxlength="12"
            type="number"
            placeholder="请输入峰值时间段服务收费金额(元/每个收费时间间隔)"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="低谷时间段服务收费(元/每个收费时间间隔)"
          prop="serviceLowEbAmount"
          v-if="this.mealDetail.serviceType === 2"
        >
          <el-input
            clearable
            v-model="mealDetail.serviceLowEbAmount"
            maxlength="12"
            type="number"
            placeholder="请输入低谷时间段服务收费金额(元/每个收费时间间隔)"
          ></el-input>
        </el-form-item> -->

        <el-form-item label="服务费标准" v-if="mealDetail.serviceType == 2">
          <el-row>
            <el-col
              :span="8"
              v-for="(item, index) in mealDetail.serviceData"
              :key="index"
            >
              <div class="powerSize">
                <div class="powerSizeTop">
                  <span>功率范围:</span>
                  {{ item.spower }}-{{ item.epower }}W
                </div>
                <div>
                  <div>
                    <span>收费:</span>
                    {{ item.chargePeakAmount / 100 }}元
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-button
            type="primary"
            :loading="loading.create"
            @click="dialog.serveShow = true"
            >重新设定</el-button
          >
        </el-form-item>

        <el-form-item
          label="服务费时间间隔(分钟)"
          prop="serviceTime"
          v-if="this.mealDetail.serviceType === 2"
        >
          <el-input
            clearable
            v-model="mealDetail.serviceTime"
            maxlength="5"
            type="number"
            style="width: 200px"
            placeholder="请输入收费时间间隔(分钟)"
          ></el-input>
        </el-form-item>

        <el-form-item label="保管收费类型" prop="custodyType">
          <el-select
            v-model="mealDetail.custodyType"
            placeholder="请选择保管收费类型"
            class="filter-item"
            style="width: 200px"
          >
            <el-option label="免费" :value="0"></el-option>
            <el-option label="按次收费" :value="1"></el-option>
            <el-option label="按时间段收费" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="保管收费(元/次)"
          prop="custodyAmount"
          v-if="this.mealDetail.custodyType == 1"
        >
          <el-input
            clearable
            v-model="mealDetail.custodyAmount"
            maxlength="12"
            type="number"
            placeholder="请输入每次保管收费金额(元/次)"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="峰值时间段保管收费(元/每个收费时间间隔)"
          prop="custodyPeakAmount"
          v-if="this.mealDetail.custodyType === 2"
        >
          <el-input
            clearable
            v-model="mealDetail.custodyPeakAmount"
            maxlength="12"
            type="number"
            placeholder="请输入峰值时间段保管收费金额(元/每个收费时间间隔)"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="低谷时间段保管收费(元/每个收费时间间隔)"
          prop="custodyLowEbAmount"
          v-if="this.mealDetail.custodyType === 2"
        >
          <el-input
            clearable
            v-model="mealDetail.custodyLowEbAmount"
            maxlength="12"
            type="number"
            placeholder="请输入低谷时间段保管收费金额(元/每个收费时间间隔)"
          ></el-input>
        </el-form-item>

        <el-form-item
          label="峰值起始时间(小时:分钟)"
          prop="peakStartTime"
          v-if="
            this.mealDetail.chargeType == 2 ||
            this.mealDetail.serviceType == 2 ||
            this.mealDetail.custodyType == 2
          "
        >
          <el-col :span="11">
            <el-time-select
              v-model="mealDetail.peakStartTime"
              :picker-options="{
                start: '00:00',
                step: `00:30`,
                end: '23:30',
              }"
              placeholder="选择时间"
            ></el-time-select>
          </el-col>
        </el-form-item>

        <el-form-item
          label="峰值结束时间(小时:分钟)"
          prop="peakEndTime"
          v-if="
            this.mealDetail.chargeType == 2 ||
            this.mealDetail.serviceType == 2 ||
            this.mealDetail.custodyType == 2
          "
        >
          <el-col :span="11">
            <el-time-select
              v-model="mealDetail.peakEndTime"
              :picker-options="{
                start: '00:00',
                step: `00:${this.mealDetail.amountTime}`,
                end: '23:30',
              }"
              placeholder="选择时间"
            ></el-time-select>
          </el-col>
        </el-form-item>
        <el-form-item
          label="对应低谷时间为(小时:分钟)"
          v-if="
            this.mealDetail.chargeType == 2 ||
            this.mealDetail.serviceType == 2 ||
            this.mealDetail.custodyType == 2
          "
        >
          <el-col :span="11">
            {{ this.mealDetail.peakEndTime }}至
            {{ this.mealDetail.peakStartTime }}
          </el-col>
        </el-form-item>
        <!-- 123 -->
        <el-form-item label="单次最低收费(元)" prop="lowAmount">
          <el-input
            clearable
            v-model="mealDetail.lowAmount"
            maxlength="12"
            type="number"
            placeholder="请输入单次最低收费(元)"
          ></el-input>
        </el-form-item>
        <el-form-item label="单次最高收费(元)" prop="tallAmount">
          <el-input
            clearable
            v-model="mealDetail.tallAmount"
            maxlength="12"
            type="number"
            placeholder="请输入单次最高收费(元)"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialog.create = false">取消</el-button>
        <el-button
          type="primary"
          :loading="loading.create"
          v-if="equipmentIdsType == ''"
          @click="crateMeal"
          >保存</el-button
        >

        <el-button
          type="primary"
          :loading="loading.create"
          v-if="equipmentIdsType == 1"
          @click="addOrUpdateList"
          >保存</el-button
        >
      </div>
    </el-dialog>
    <!-- 功率收费设置 -->
    <el-dialog
      title="设置收费标准"
      :visible.sync="dialog.powerSetVisible"
      @close="(dialog.powerSetVisible = false), (powerFormVisible = false)"
    >
      <el-form label-position="top">
        <el-form-item label="收费标准">
          <el-row>
            <el-col
              :span="6"
              v-for="(item, index) in mealDetail.chargePowerData"
              :key="index"
            >
              <div
                :class="powerSizeClass[index]"
                @click="changeChargeMealVisible(item, index)"
              >
                <div class="powerSizeTop">
                  <span>功率范围:</span>
                  {{ item.spower }}-{{ item.epower }}W
                </div>
                <div>
                  <div>
                    <span>峰值收费:</span>
                    {{ divide(item.chargePeakAmount,100) }}元
                  </div>
                  <div>
                    <span>低谷收费:</span>
                    {{ divide(item.chargeLowEbAmount,100) }}元
                  </div>
                </div>
              </div>
            </el-col>

            <el-col :span="24">
              <el-button
                type="primary"
                :loading="loading.create"
                @click="changeChargeMealVisible()"
                v-if="mealDetail.chargePowerData.length < 8"
                >新增</el-button
              >
              <!--  -->
              <el-button
                type="primary"
                :loading="loading.create"
                v-if="mealDetail.chargePowerData.length > 0"
                @click="delPowerSize"
                >删除</el-button
              >
              <!--  -->
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>

      <div
        v-if="powerFormVisible"
        style="width: 60%; border: 1px solid #dcdfe6; padding: 10px"
      >
        <el-form
          :model="powerForms"
          :rules="powerRules"
          ref="powerForm"
          label-position="top"
        >
          <el-form-item label="功率段起始功率(W):" prop="spower">
            <el-input
              clearable
              v-model="powerForms.spower"
              maxlength="4"
              type="number"
              :disabled="powerForms.disabledSpower"
            ></el-input>
          </el-form-item>
          <el-form-item label="功率段结束功率(W):" prop="epower">
            <el-input
              clearable
              v-model="powerForms.epower"
              maxlength="4"
              type="number"
              :disabled="powerForms.disabledEpower"
            ></el-input>
          </el-form-item>

          <el-form-item
            label="峰值价格(元/每个收费时间间隔):"
            prop="chargePeakAmount"
          >
            <el-input
              clearable
              v-model="powerForms.chargePeakAmount"
              maxlength="4"
              type="number"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="低谷价格(元/每个收费时间间隔):"
            prop="chargeLowEbAmount"
          >
            <el-input
              clearable
              @input="changeChargeLowEbAmount"
              v-model="powerForms.chargeLowEbAmount"
              maxlength="4"
              type="number"
            ></el-input>
          </el-form-item>

          <el-button
            type="primary"
            :loading="loading.create"
            @click="cancelChangeChargeMeal"
            style="margin-top: 10px"
            >取消</el-button
          >
          <el-button
            type="primary"
            :loading="loading.create"
            @click="changeChargeMeal()"
            style="margin-top: 10px"
            >确定输入</el-button
          >
          <!-- </el-row>
          </el-col>
          </el-row>-->
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialog.create = false">取消</el-button>
        <el-button
          type="primary"
          :loading="loading.create"
          v-if="equipmentIdsType==''"
          @click="crateMeal"
        >保存</el-button>-->

        <el-button
          type="primary"
          :loading="loading.powerSetVisible"
          @click="(dialog.powerSetVisible = false), (powerFormVisible = false)"
          >确定</el-button
        >
      </div>
    </el-dialog>

    <!-- 服务费设置 -->
    <el-dialog
      title="服务费标准"
      :visible.sync="dialog.serveShow"
      @close="(dialog.serveShow = false), (powerFormVisible = false)"
    >
      <el-form label-position="top">
        <el-form-item label="收费标准">
          <el-row>
            <el-col
              :span="6"
              v-for="(item, index) in mealDetail.serviceData"
              :key="index"
            >
              <div
                :class="powerSizeClass[index]"
                @click="changeChargeMealVis2(item, index)"
              >
                <div class="powerSizeTop">
                  <span>功率范围:</span>
                  {{ item.spower }}-{{ item.epower }}W
                </div>
                <div>
                  <div>
                    <span>收费:</span>
                    {{ item.chargePeakAmount / 100 }}元
                  </div>
                </div>
              </div>
            </el-col>

            <el-col :span="24">
              <el-button
                type="primary"
                :loading="loading.create"
                @click="changeChargeMealVis2()"
                v-if="mealDetail.serviceData.length < 8"
                >新增</el-button
              >
              <!--  -->
              <el-button
                type="primary"
                :loading="loading.create"
                v-if="mealDetail.serviceData.length > 0"
                @click="delPowerSize2"
                >删除</el-button
              >
              <!--  -->
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>

      <div
        v-if="powerFormVisible"
        style="width: 60%; border: 1px solid #dcdfe6; padding: 10px"
      >
        <el-form
          :model="powerForms"
          :rules="powerRules"
          ref="powerForm"
          label-position="top"
        >
          <el-form-item label="功率段起始功率(W):" prop="spower">
            <el-input
              clearable
              v-model="powerForms.spower"
              maxlength="4"
              type="number"
              :disabled="powerForms.disabledSpower"
            ></el-input>
          </el-form-item>
          <el-form-item label="功率段结束功率(W):" prop="epower">
            <el-input
              clearable
              v-model="powerForms.epower"
              maxlength="4"
              type="number"
              :disabled="powerForms.disabledEpower"
            ></el-input>
          </el-form-item>

          <el-form-item
            label="价格(元/每个收费时间间隔):"
            prop="chargePeakAmount"
          >
            <el-input
              clearable
              v-model="powerForms.chargePeakAmount"
              maxlength="4"
              type="number"
            ></el-input>
          </el-form-item>

          <el-button
            type="primary"
            :loading="loading.create"
            @click="cancelChangeChargeM2"
            style="margin-top: 10px"
            >取消</el-button
          >
          <el-button
            type="primary"
            :loading="loading.create"
            @click="changeChargeMeal2()"
            style="margin-top: 10px"
            >确定输入</el-button
          >
          <!-- </el-row>
          </el-col>
          </el-row>-->
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialog.create = false">取消</el-button>
        <el-button
          type="primary"
          :loading="loading.create"
          v-if="equipmentIdsType==''"
          @click="crateMeal"
        >保存</el-button>-->

        <el-button
          type="primary"
          :loading="loading.serveShow"
          @click="(dialog.serveShow = false), (powerFormVisible = false)"
          >确定</el-button
        >
      </div>
    </el-dialog>
    <!-- 卡套餐 -->
    <el-dialog title="设置设备卡套餐" :visible.sync="dialog.addEquipmentCard">
      <el-form
        :model="EquipmentCardinfo"
        :rules="EquipmentCardRules"
        ref="EquipmentCardForm"
        label-position="right"
        label-width="180px"
      >
        <el-form-item label="设备编号" prop="equipmentNumber">
          <el-input
            v-model="EquipmentCardinfo.equipmentNumber"
            :disabled="true"
            maxlength="50"
            placeholder="请输入设备编号"
          ></el-input>
        </el-form-item>
        <el-form-item label="设备地址" prop="address">
          <el-input
            :disabled="true"
            v-model="EquipmentCardinfo.address"
            maxlength="50"
          ></el-input>
        </el-form-item>

        <!-- <el-form-item label="时长(天)" prop="timeDay">
          <el-input v-model="EquipmentCardinfo.timeDay" maxlength="12" placeholder="请输入时长 大于0的正整数"></el-input>
        </el-form-item>-->
        <el-form-item label="使用时长(小时)" prop="useTimeQuantum">
          <el-input
            v-model="EquipmentCardinfo.useTimeQuantum"
            maxlength="12"
            placeholder="请输入使用时长 大于0的正整数"
          ></el-input>
        </el-form-item>
        <el-form-item label="有效时长(天)" prop="timeDay">
          <el-input
            v-model="EquipmentCardinfo.timeDay"
            maxlength="12"
            placeholder="请输入有效时长 大于0的正整数"
          ></el-input>
        </el-form-item>
        <el-form-item label="套餐所需金额(元)" prop="amount">
          <el-input
            v-model="EquipmentCardinfo.amount"
            maxlength="12"
            placeholder="套餐所需金额(元)"
          ></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialog.addEquipmentCard = false">取消</el-button>

        <el-button
          type="primary"
          :loading="loading.addEquipmentCard"
          @click="addCard"
          v-if="this.equipmentIdsType == ''"
          >确定</el-button
        >
        <el-button
          type="primary"
          :loading="loading.addEquipmentCard"
          v-if="this.equipmentIdsType == 2"
          @click="addEquipmentCardList"
          >确定</el-button
        >
      </div>
    </el-dialog>
    <!-- 设备状态数据 -->
    <el-dialog title="设备状态数据" :visible.sync="showStatus" width="500px">
      <el-form
        :model="equipmentOtherData"
        label-position="right"
        label-width="180px"
      >
        <el-form-item label="烟雾传感器状态：" prop="smokeStatus">
          <el-col
            :span="11"
            :style="
              equipmentOtherData.smokeStatus == 1
                ? 'color: #37b328'
                : 'color: red'
            "
          >
            {{ equipmentOtherData.smokeStatus == 1 ? "正常" : "异常" }}
          </el-col>
        </el-form-item>
        <el-form-item label="火灾状况：" prop="fireArea">
          <el-col
            v-if="equipmentOtherData.fireArea.length < 1"
            :span="11"
            style="color: #37b328"
          >
            无火灾
          </el-col>
          <template v-else>
            <el-col
              v-for="(item, index) in equipmentOtherData.fireArea"
              :key="index"
              :span="11"
              style="color: red"
            >
              {{
                item == 1
                  ? "区域一有火灾"
                  : item == 2
                  ? "区域二有火灾"
                  : item == 3
                  ? "区域三有火灾"
                  : "区域四有火灾"
              }}
            </el-col>
          </template>
        </el-form-item>

        <el-form-item label="火灾标志：" prop="fireSign">
          <el-col
            :span="11"
            :style="
              equipmentOtherData.fireSign == 0 ? 'color: #37b328' : 'color: red'
            "
          >
            {{ equipmentOtherData.fireSign == 1 ? "有火灾" : "无火灾" }}
          </el-col>
        </el-form-item>

        <el-form-item label="微动开关：" prop="microSwitch">
          <el-col
            :span="11"
            :style="
              equipmentOtherData.microSwitch == 0
                ? 'color: #37b328'
                : 'color: red'
            "
          >
            {{ equipmentOtherData.microSwitch == 1 ? "警告" : "无警告" }}
          </el-col>
        </el-form-item>
        <el-form-item label="液位警告：" prop="levelWarning">
          <el-col
            :span="11"
            :style="
              equipmentOtherData.levelWarning == 0
                ? 'color: #37b328'
                : 'color: red'
            "
          >
            {{ equipmentOtherData.levelWarning == 1 ? "液位异常" : "液位正常" }}
          </el-col>
        </el-form-item>

        <el-form-item label="自检灯状态：" prop="selfCheckStatus">
          <el-col
            :span="11"
            :style="
              equipmentOtherData.selfCheckStatus == 15
                ? 'color: #37b328'
                : 'color: red'
            "
          >
            {{ equipmentOtherData.selfCheckStatus == 15
                  ? "正常"
                  : equipmentOtherData.selfCheckStatus == 7
                  ? "第1个灯异常"
                  : equipmentOtherData.selfCheckStatus == 11
                  ? "第2个灯异常"
                  : equipmentOtherData.selfCheckStatus == 13
                  ? "第3个灯异常"
                  : equipmentOtherData.selfCheckStatus == 14
                  ? "第4个灯异常"
                  : equipmentOtherData.selfCheckStatus == 6
                  ? "第1、4个灯异常"
                  : equipmentOtherData.selfCheckStatus == 9
                  ? "第2、3个灯异常"
                  : equipmentOtherData.selfCheckStatus == 10
                  ? "第2、4个灯异常"
                  : equipmentOtherData.selfCheckStatus == 12
                  ? "第3、4个灯异常"
                  : equipmentOtherData.selfCheckStatus == 1
                  ? "第1、2、3个灯异常"
                  : equipmentOtherData.selfCheckStatus == 2
                  ? "第1、2、4个灯异常"
                  : equipmentOtherData.selfCheckStatus == 4
                  ? "第1、3、4个灯异常"
                  : equipmentOtherData.selfCheckStatus == 8
                  ? "第2、3、4个灯异常"
                  : equipmentOtherData.selfCheckStatus == 0
                  ? "所有灯异常" : ''
                  }}
          </el-col>
        </el-form-item>

        <el-form-item label="应急开关：" prop="emergencySwitch">
          <el-col
            :span="11"
            :style="
              equipmentOtherData.emergencySwitch == 0
                ? 'color: #37b328'
                : 'color: red'
            "
          >
            {{ equipmentOtherData.emergencySwitch == 1 ? "异常" : "正常" }}
          </el-col>
        </el-form-item>

        <el-form-item label="水浸传状态：" prop="waterSensorStatus">
          <el-col
            :span="11"
            :style="
              equipmentOtherData.waterSensorStatus == 1
                ? 'color: #37b328'
                : 'color: red'
            "
          >
            {{ equipmentOtherData.waterSensorStatus == 1 ? "正常" : "异常" }}
          </el-col>
        </el-form-item>

        <el-form-item label="水箱水位状态：" prop="waterTankStatus">
          <el-col
            :span="11"
            :style="
              equipmentOtherData.waterTankStatus == 1
                ? 'color: #37b328'
                : 'color: red'
            "
          >
            {{ equipmentOtherData.waterTankStatus == 1 ? "正常" : "异常" }}
          </el-col>
        </el-form-item>
        <el-form-item label="电池电压：" prop="cellVoltage">
          <el-col
            v-if="equipmentOtherData.cellVoltage"
            :span="11"
            style="color: #37b328"
          >
            {{ equipmentOtherData.equipmentType }} V
          </el-col>
          <el-col v-else :span="11" style="color: #37b328"> 无 </el-col>
        </el-form-item>
        <el-table
          :data="equipmentOtherData.list"
          style="width: 100%"
          v-show="equipmentOtherData.equipmentType == 5"
        >
          <el-table-column label="格口编号" prop="mouthNoShow" align="center" />
          <el-table-column label="充电状态" prop="mouthStatus" align="center">
            <template slot-scope="scope">
              <div>
                {{
                  scope.row.mouthStatus == 0
                    ? "空闲"
                    : scope.row.mouthStatus == 1
                    ? "充电中"
                    : scope.row.mouthStatus == 2
                    ? "电池充满"
                    : scope.row.mouthStatus == 3
                    ? "限额充电"
                    : scope.row.mouthStatus == 4
                    ? "电池识别异常"
                    : scope.row.mouthStatus == 5
                    ? "输出短路故障"
                    : scope.row.mouthStatus == 6
                    ? "输出过压"
                    : scope.row.mouthStatus == 7
                    ? "输出过流"
                    : scope.row.mouthStatus == 8
                    ? "系统过温"
                    : scope.row.outhStatus == 9
                    ? "NTC异常"
                    : scope.row.mouthStatus == 10
                    ? "电池故障"
                    : scope.row.mouthStatus == 11
                    ? "负载断电"
                    : scope.row.mouthStatus == 12
                    ? "电源故障"
                    : scope.row.mouthStatus == 13
                    ? "通讯超时"
                    : scope.row.mouthStatus == 14
                    ? "过压关机"
                    : scope.row.mouthStatus == 15
                    ? "电池反接"
                    : scope.row.mouthStatus == 16
                    ? "充电超时"
                    : "-"
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="门状态" prop="doorStatus" align="center">
            <template slot-scope="scope">
              <div>
                {{
                  scope.row.doorStatus == 0
                    ? "开"
                    : scope.row.doorStatus == 1
                    ? "关"
                    : scope.row.doorStatus == 2
                    ? "超时"
                    : scope.row.doorStatus == 2
                    ? "异常"
                    : "-"
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="温度" prop="temperature" align="center" />
          <el-table-column label="功率" prop="power" align="center" />
        </el-table>

         <div  style="display:flex;justify-content:end;margin-top:10px">
          <el-button
          style="margin-right:10px"
            type="primary"
            @click="
              getEquipmentOtherData(
                equipmentOtherData.equipmentId,
                equipmentOtherData.deviceId,
                equipmentOtherData.equipmentNumber,
                equipmentOtherData.equipmentType,
              )
            "
            >刷新</el-button
          >
          <el-button
            type="primary"
            @click="
              equipmentOtherCmd(
                equipmentOtherData.equipmentId,
                equipmentOtherData.deviceId,
                equipmentOtherData.equipmentNumber,
                equipmentOtherData.equipmentType,
              )
            "
            >下发查询命令</el-button
          >
        </div>

      </el-form>
    </el-dialog>

    <!-- 展示二维码图片 -->
    <el-dialog title="二维码" :visible.sync="dialogVisible" width="500px">
      <img
        :src="showPic"
        alt
        style="width: 400px; display: block; margin: 0 auto 30px"
      />
    </el-dialog>
    <!-- dialog 查看图片弹窗 -->
    <el-dialog title :visible.sync="dialog.view">
      <el-carousel type="card" trigger="click" style="text-align: center">
        <el-carousel-item v-for="item in imgList" :key="item">
          <img :src="item" style="max-height: 310px; width: 350px" />
        </el-carousel-item>
      </el-carousel>
    </el-dialog>
    <!-- 回到顶部 -->
    <BackToTop></BackToTop>
  </div>
</template>
<script>
import {
  getEquipmentList,
  addtem,
  delEquipment,
  updateItem,
  getEquipmentMeal,
  addEquipmentMeal,
  updateEquipmentExcel,
  addEquipmentCard,
  updateEquipmentCard,
  delEquipmentCard,
  getEquipmentCardList,
  updateTrumpet,
  downLoadExcel,
  getOneNetData,
  updateIsFlag,
  addOrUpdate,
  getManagerList,
  getEquipmentOtherData,
} from "@/api/equipment";
import {
  addOrUpdateList,
  addCardTypeList,
  addEquipmentExcel,
} from "@/api/equipmentOverTime";
import { getBackAgentBox } from "@/api/adminEnt";
import {
  getAddressByAreaId,
  getId,
  getAddress,
  getObjByName,
  getObjByAreaId,
  getByNameProvinceId,
  getByNameCityId,
  getByNameAreaId,
} from "@/utils/getAddress";
import {
  updateSystemParamter,
  getSystemParamter,
  fileUpload,
  addSystemParamter,
} from "@/api/system";
import { getData, cmd } from "@/api/equipmentOther";
import BackToTop from "@/components/BackToTop";
import axios from "axios";
import VePie from "v-charts/lib/pie";
import pcq from "@/components/index";
import Velocity from "velocity-animate";
import "velocity-animate/velocity.ui.js";
import { parseTime } from "@/utils";
import { Message, Notification, Loading } from "element-ui";
import store from "@/store";
import mixin from '@/utils/mathUtils.js'
export default {
  name: "equipment_list",
  mixins: [mixin],
  components: {
    BackToTop,
    VePie,
    pcq,
  },
  data() {
    var authInfoTest = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("鉴权信息不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^[A-Za-z0-9]{0,512}$/;
        if (!isNum.test(value)) {
          callback(new Error("鉴权信息长度在1~512之间，只能包含字母,数字!"));
        } else {
          callback();
        }
      }, 300);
    };
    var equipmentNumberTest = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("设备编号不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^[0-9]{7}$/;
        if (!isNum.test(value)) {
          callback(new Error("设备编号长度为7，只能包含数字"));
        } else {
          callback();
        }
      }, 300);
    };
    var validateDay = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("时长不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^[1-9]\d*$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入大于0的正整数!"));
        }
        if ((value + "").length > 12) {
          callback(new Error("时长超过范围,12位"));
        }
        callback();
      }, 300);
    };
    var validateUseTimeQuantum = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("时长不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^[1-9]\d*$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入大于0的正整数!"));
        }
        if ((value + "").length > 12) {
          callback(new Error("时长超过范围,12位"));
        }
        callback();
      }, 300);
    };
    var validateNum = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，两位小数以内!"));
        } else {
          if ((value + "").length > 12) {
            callback(new Error("金额超过范围,12位"));
          }
          callback();
        }
      }, 300);
    };
    var validatePowerFormData = (rule, value, callback) => {
      if (!this.mealDetail.chargePowerData.length) {
        return callback(new Error("收费标准不能为空!"));
      }
      // setTimeout(() => {
      //   var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
      //   if (!isNum.test(value)) {
      //     callback(new Error("请输入正确金额,金额不能小于等0，两位小数以内!"));
      //   } else {
      //     if ((value + "").length > 12) {
      //       callback(new Error("金额超过范围,12位"));
      //     }
      //     callback();
      //   }
      // }, 300);
    };
    var validateChargePeak = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，两位小数以内!"));
        } else {
          if ((value + "").length > 12) {
            callback(new Error("金额超过范围,12位"));
          }
          callback();
        }
      }, 300);
    };
    var validateChargeLow = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，两位小数以内!"));
        } else {
          if ((value + "").length > 12) {
            callback(new Error("金额超过范围,12位"));
          }
          callback();
        }
      }, 300);
    };
    var validateChargePowerData = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，两位小数以内!"));
        } else {
          if ((value + "").length > 12) {
            callback(new Error("金额超过范围,12位"));
          }
          callback();
        }
      }, 300);
    };
    var valServicePeak = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，两位小数以内!"));
        } else {
          if ((value + "").length > 12) {
            callback(new Error("金额超过范围,12位"));
          }
          callback();
        }
      }, 300);
    };

    var valChargeAmountTime = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("时间间隔不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(1|([1-9]\d*))$/;
        if (!isNum.test(value)) {
          callback(new Error("时间间隔为大于0的正整数!"));
        } else {
          if ((value + "").length > 3) {
            callback(new Error("时间间隔长度超过范围3位"));
          }
          callback();
        }
      }, 300);
    };

    var valServiceLow = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，两位小数以内!"));
        } else {
          if ((value + "").length > 12) {
            callback(new Error("金额超过范围,12位"));
          }
          callback();
        }
      }, 300);
    };
    var valCustodyPeak = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("该处不能为空"));
      }
      setTimeout(() => {
        if (value <= 0) {
          callback(new Error("请输入大于0的正数"));
        } else {
          if (value < this.mealDetail.custodyLowEbAmount) {
            callback(
              new Error("请输入大于低谷时间段的收费金额(元/每个收费时间间隔)")
            );
          } else {
            callback();
          }
        }
      }, 1000);
    };
    var valCustodyLow = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，两位小数以内!"));
        } else {
          if ((value + "").length > 12) {
            callback(new Error("金额超过范围,12位"));
          }
          callback();
        }
      }, 300);
    };
    var valTallAmount = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，两位小数以内!"));
        } else {
          if ((value + "").length > 12) {
            callback(new Error("金额超过范围,12位"));
          }
          callback();
        }
      }, 300);
    };

    var validateLowAmount = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,4}|[1-9][0-9]*\.\d{1,4})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，四位小数以内!"));
        } else {
          if ((value + "").length > 14) {
            callback(new Error("金额超过范围,14位"));
          }
          callback();
        }
      }, 300);
    };

    var validateTallAmount = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,4}|[1-9][0-9]*\.\d{1,4})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，四位小数以内!"));
        } else {
          if ((value + "").length > 14) {
            callback(new Error("金额超过范围,14位"));
          }
          if (Number(this.mealDetail.lowAmount * 10000) >= Number(value * 10000)) {
            callback(new Error("不能小于或等于 单次最低金额"));
          }
          callback();
        }
      }, 300);
    };
    var valLowAmount = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("金额不能为空!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入正确金额,金额不能小于等0，两位小数以内!"));
        } else {
          if ((value + "").length > 12) {
            callback(new Error("金额超过范围,12位"));
          }
          callback();
        }
      }, 300);
    };
    var valSpower = (rule, value, callback) => {
      // if (!value) {
      //   return callback(new Error("起始功率不能为空!"));
      // } else
      if (this.powerForms.epower <= this.powerForms.spower) {
        return callback(new Error("同一功率段起始功率应小于结束功率!"));
      }
      setTimeout(() => {
        var isNum = /^(0|([1-9]\d{0,2}))$/;

        if (!isNum.test(value)) {
          callback(new Error("请输入起始功率,起始功率应该为0-1000之间的整数"));
        } else {
          if ((value + "").length > 4) {
            callback(new Error("起始功率超过范围,4位"));
          }
          callback();
        }
      }, 300);
    };
    var valEpower = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("结束功率不能为空!"));
      } else if (this.powerForms.epower <= this.powerForms.spower) {
        return callback(new Error("同一功率段结束功率应大于起始功率!"));
      }
      setTimeout(() => {
        var isNum = /^(0|([1-9]\d{0,2}))$/;
        if (!isNum.test(value)) {
          callback(new Error("请输入结束功率,结束功率应该为1-999之间的整数!"));
        } else {
          if ((value + "").length > 4) {
            callback(new Error("起始功率超过范围,4位"));
          }
          callback();
        }
      }, 300);
    };
    var valChargeLowEbAmount = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("低谷充电价格不能为空!"));
      } else if (
        this.powerForms.chargePeakAmount < this.powerForms.chargeLowEbAmount
      ) {
        return callback(new Error("低谷充电价格应小于峰值充电价格!"));
      }

      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,4}|[1-9][0-9]*\.\d{1,4})))$/;
        // console.log("3311");
        if (value <= 0) {
          callback(new Error("充电价格应大于0!"));
          // console.log("3312");
        } else if (!isNum.test(value)) {
          callback(
            new Error(
              "请输入低谷充电价格,低谷充电价格不能小于等0，四位小数以内!"
            )
          );
        } else {
          if ((value + "").length > 6) {
            callback(new Error("低谷充电价格超过范围,6位"));
          }
          callback();
        }
      }, 300);
    };
    var valChargePeakAmount = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("峰值充电价格不能为空!"));
      } else if (
        this.powerForms.chargePeakAmount < this.powerForms.chargeLowEbAmount
      ) {
        return callback(new Error("峰值充电价格应大于低谷充电价格!"));
      }
      setTimeout(() => {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,4}|[1-9][0-9]*\.\d{1,4})))$/;
        if (this.powerForms.chargePeakAmount <= 0) {
          callback(new Error("充电价格应大于0!"));
        } else if (!isNum.test(value)) {
          callback(
            new Error(
              "请输入峰值充电价格,峰值充电价格不能小于等0，四位小数以内!"
            )
          );
        } else {
          if ((value + "").length > 6) {
            callback(new Error("峰值充电价格超过范围,6位"));
          }
          callback();
        }
      }, 300);
    };

    return {
      dateTime: "",
      showStatus: false,
      // 设备状态
      equipmentOtherData: {
        equipmentId: "",
        deviceId: "",
        smokeStatus: "",
        waterSensorStatus: "",
        waterTankStatus: "",
        cellVoltage: "",
        list: {},
        fireArea: [], //火灾区域
        fireSign: "", //火灾标志
        microSwitch: "", //微动开关
        levelWarning: "", //液位警告
        selfCheckStatus: "", //自检灯状态
        emergencySwitch: "", //应急开关
        equipmentType: "",
      },
      //选择框显示
      selectionView: false,
      selectionArray: null,
      equipmentIds: null,
      cardTypeIds: null,
      equipmentIdsType: "",
      updataTip: "批量新增",
      tableTemp: [
        {
          equipmentNumber: "",
          authInfo: "",
          equipmentType: "",
          province: "",
          city: "",
          area: "",
          equipmentAddress: "",
          companyId: "",
        },
      ],
      mealDetail: {
        mealId: null,
        equipmentId: null,
        chargeType: 1,
        chargeAmount: 0,
        chargePeakAmount: 0,
        chargeLowEbAmount: 0,
        serviceType: 0,
        serviceAmount: 0,
        servicePeakAmount: 0,
        serviceLowEbAmount: 0,
        custodyType: 0,
        custodyAmount: 0,
        custodyPeakAmount: 0,
        custodyLowEbAmount: 0,
        amountTime: 240,
        serviceTime: 240,
        lowAmount: 0,
        tallAmount: 0,
        peakStartTime: "00:00",
        peakEndTime: "00:00",
        lowEbStartTime: "00:00",
        lowEbEndTime: "00:00",
        chargePowerData: [
          {
            chargeLowEbAmount: 100,
            chargePeakAmount: 200,
            spower: 0,
            epower: 150,
          },
          {
            chargeLowEbAmount: 200,
            chargePeakAmount: 300,
            spower: 150,
            epower: 200,
          },
          {
            chargePeakAmount: 300,
            chargeLowEbAmount: 400,
            spower: 200,
            epower: 250,
          },
          {
            chargeLowEbAmount: 400,
            chargePeakAmount: 500,
            spower: 250,
            epower: 300,
          },
          {
            chargeLowEbAmount: 500,
            chargePeakAmount: 600,
            spower: 300,
            epower: 350,
          },
          {
            chargeLowEbAmount: 600,
            chargePeakAmount: 700,
            spower: 350,
            epower: 400,
          },
          {
            chargeLowEbAmount: 700,
            chargePeakAmount: 800,
            spower: 400,
            epower: 450,
          },
        ],
        serviceData: [
        {
          chargePeakAmount: 100,
          spower: 0,
          epower: 150,
        },
        {
          chargePeakAmount: 200,
          spower: 150,
          epower: 200,
        },
        {
          chargePeakAmount: 300,
          spower: 200,
          epower: 250,
        },
        {
          chargePeakAmount: 400,
          spower: 250,
          epower: 300,
        },
        {
          chargePeakAmount: 500,
          spower: 300,
          epower: 350,
        },
        {
          chargePeakAmount: 600,
          spower: 350,
          epower: 400,
        },
        {
          chargePeakAmount: 700,
          spower: 400,
          epower: 450,
        },
      ],
      },
      isCrate: 1,
      defaultChargePowerData: [
        {
          chargeLowEbAmount: 100,
          chargePeakAmount: 200,
          spower: 0,
          epower: 150,
        },
        {
          chargeLowEbAmount: 200,
          chargePeakAmount: 300,
          spower: 150,
          epower: 200,
        },
        {
          chargePeakAmount: 300,
          chargeLowEbAmount: 400,
          spower: 200,
          epower: 250,
        },
        {
          chargeLowEbAmount: 400,
          chargePeakAmount: 500,
          spower: 250,
          epower: 300,
        },
        {
          chargeLowEbAmount: 500,
          chargePeakAmount: 600,
          spower: 300,
          epower: 350,
        },
        {
          chargeLowEbAmount: 600,
          chargePeakAmount: 700,
          spower: 350,
          epower: 400,
        },
        {
          chargeLowEbAmount: 700,
          chargePeakAmount: 800,
          spower: 400,
          epower: 450,
        },
      ],
      serviceData: [
        {
          chargePeakAmount: 100,
          spower: 0,
          epower: 150,
        },
        {
          chargePeakAmount: 200,
          spower: 150,
          epower: 200,
        },
        {
          chargePeakAmount: 300,
          spower: 200,
          epower: 250,
        },
        {
          chargePeakAmount: 400,
          spower: 250,
          epower: 300,
        },
        {
          chargePeakAmount: 500,
          spower: 300,
          epower: 350,
        },
        {
          chargePeakAmount: 600,
          spower: 350,
          epower: 400,
        },
        {
          chargePeakAmount: 700,
          spower: 400,
          epower: 450,
        },
      ],
      //
      powerFormList: {},
      powerForms: {
        chargePeakAmount: "",
        chargeLowEbAmount: "",
        spower: "",
        epower: "",
        disabledSpower: false,
        disabledEpower: false,
      },
      powerFormVisible: false,
      powerSizeClass: [
        "powerSize",
        "powerSize",
        "powerSize",
        "powerSize",
        "powerSize",
        "powerSize",
        "powerSize",
        "powerSize",
        "powerSize",
        "powerSize",
      ],
      EquipmentCardinfo: {
        status: 1,
        cardType: 2,
        area: "",
        city: "",
        equipmentId: "",
        equipmentNumber: "",
        timeDay: "",
        amount: "",
        address: "",
        cardTypeId: "",
        useTimeQuantum: "",
      },
      value: "",
      provices: [],
      cities: [],
      areas: [],
      pId: "",
      cId: "",
      dialogType: "",
      chartData: null,
      companyList: [],
      agentList: [],
      loading: {
        list: false,
        add: false,
        detele: false,
        upd: false,
        create: false,
        addEquipmentCard: false,
        powerSetVisible: false,
        serveShow: false
      },
      dialog: {
        bind: false,
        add: false,
        upd: false,
        view: false,
        create: false,
        addEquipmentCard: false,
        powerSetVisible: false,
        serveShow: false
      },
      imgList: [],
      total: 0,
      downloadLoading: false,
      updataLoading: false,
      exlDownloadLoading: false,
      date: "",
      listQuery: {
        offset: 1,
        limit: 10,
        userName: "",
        authInfo: "",
        equipmentId: "",
        equipmentNumber: "",
        deviceId: "",
        address: "",
        equipmentType: "",
        maxCellVoltage: "",
        equipmentStatus: "",
        startTime: "",
        endTime: "",
      },
      addQuery: {
        equipmentId: "",
        equipmentNumber: "",
        deviceId: "",
        companyId: "",
        province: "",
        city: "",
        area: "",
        equipmentAddress: "",
        managerId: "",
      },
      bindQuery: {
        equipmentNumber: "",
        equipmentCode: "",
        equipmentType: "",
      },
      // 设备规则
      bindRules: {
        equipmentNumber: [
          { required: true, message: "设备编号不能为空!", trigger: "change" },
          { validator: equipmentNumberTest, trigger: "change" },
        ],
        deviceId: [
          { required: true, message: "deviceId不能为空!", trigger: "change" },
          // { validator: authInfoTest, trigger: "change" },
        ],
        equipmentType: [
          { required: true, message: "请选择设备类型", trigger: "change" },
        ],
        province: [{ required: true, message: "请选择省", trigger: "change" }],
        city: [{ required: true, message: "请选择市", trigger: "change" }],
        area: [{ required: true, message: "请选择区", trigger: "change" }],
        equipmentAddress: [
          { required: true, message: "详细地址不能为空!", trigger: "change" },
        ],
        companyId: [
          {
            required: true,
            message: "请选择省级全资子公司!",
            trigger: "change",
          },
        ],
      },
      // 套餐规则
      mealRules: {
        peakStartTime: [
          {
            required: true,
            message: "设置峰值起始时间(小时:分钟)",
            trigger: "change",
          },
        ],
        peakEndTime: [
          {
            required: true,
            message: "设置峰值结束时间(小时:分钟)",
            trigger: "change",
          },
        ],
        chargeAmount: [
          {
            required: true,
            message: "请输入充电收费价格(元/次)!",
            trigger: "change",
          },
          { validator: validateNum, trigger: "change" },
        ],

        serviceAmount: [
          {
            required: true,
            message: "请输入每次服务收费金额(元/次)!",
            trigger: "change",
          },
          { validator: validateNum, trigger: "change" },
        ],
        servicePeakAmount: [
          {
            required: true,
            message: "请输入峰值时间段服务收费金额(元/每个收费时间间隔)!",
            trigger: "change",
          },
          { validator: valServicePeak, trigger: "change" },
        ],
        serviceLowEbAmount: [
          {
            required: true,
            message: "请输入低谷时间段服务收费金额(元/每个收费时间间隔)!",
            trigger: "change",
          },
          { validator: valServiceLow, trigger: "change" },
        ],
        custodyAmount: [
          {
            required: true,
            message: "请输入每次保管收费金额(元/次)!",
            trigger: "change",
          },
          { validator: validateNum, trigger: "change" },
        ],
        custodyPeakAmount: [
          {
            required: true,
            message: "请输入峰值时间段保管收费金额(元/每个收费时间间隔)!",
            trigger: "change",
          },
          { validator: valCustodyPeak, trigger: "change" },
        ],
        custodyLowEbAmount: [
          {
            required: true,
            message: "请输入低谷时间段保管收费金额(元/每个收费时间间隔)!",
            trigger: "change",
          },
          { validator: valCustodyLow, trigger: "change" },
        ],
        lowAmount: [
          {
            required: true,
            message: "请输入单次最低收费(元)!",
            trigger: "change",
          },
          { validator: validateLowAmount, trigger: "change" },
        ],
        tallAmount: [
          {
            required: true,
            message: "请输入单次最高收费(元)!",
            trigger: "change",
          },
          { validator: validateTallAmount, trigger: "change" },
        ],
        amountTime: [
          {
            required: true,
            message: "请输入收费时间间隔",
            trigger: "blur",
          },
          { validator: valChargeAmountTime, trigger: "change" },
        ],
        serviceTime: [
          {
            required: true,
            message: "请输入服务费时间间隔",
            trigger: "blur",
          },
          { validator: valChargeAmountTime, trigger: "change" },
        ],
      },
      mealForm: {
        validateNum: "",
        valServicePeak: "",
        valServiceLow: "",
        valCustodyPeak: "",
        valCustodyLow: "",
        valLowAmount: "",
        valTallAmount: "",
      },
      // 功率段设置规则
      powerRules: {
        spower: [
          {
            required: true,
            message: "请输入起始功率(W)!",
            trigger: "change",
          },
          { validator: valSpower, trigger: "changer" },
        ],
        epower: [
          {
            required: true,
            message: "请输入结束功率(W)!",
            trigger: "change",
          },
          { validator: valEpower, trigger: "change" },
        ],
        chargePeakAmount: [
          {
            required: true,
            message: "请输入峰值充电价格(元/每个收费时间间隔)!",
            trigger: "change",
          },
          { validator: valChargePeakAmount, trigger: "change" },
        ],
        chargeLowEbAmount: [
          {
            required: true,
            message: "请输入低谷充电价格(元/每个收费时间间隔)!",
            trigger: "change",
          },
          { validator: valChargeLowEbAmount, trigger: "change" },
        ],
      },
      powerForm: {
        valSpower: "",
        valEpower: "",
        valChargePeakAmount: "",
        valChargeLowEbAmount: "",
      },
      //设备卡规则
      EquipmentCardRules: {
        timeDay: [
          {
            required: true,
            message: "时长(天)",
            trigger: "blur",
          },
          { validator: validateDay, trigger: "change" },
        ],
        useTimeQuantum: [
          {
            required: true,
            message: "时长(天)",
            trigger: "blur",
          },
          { validator: validateUseTimeQuantum, trigger: "change" },
        ],
        amount: [
          {
            required: true,
            message: "金额(元)",
            trigger: "blur",
          },
          { validator: validateNum, trigger: "change" },
        ],
      },
      EquipmentCardForm: {
        timeDay: "",
        useTimeQuantum: "",
        amount: "",
      },
      //
      equipmentTypeOptions: [
        { value: 1, label: "交流" },
        { value: 2, label: "交直流-单模块" },
        { value: 3, label: "交直流-双模块" },
        { value: 5, label: "充电柜"}
      ],
      //  设备绑定的套餐
      equipmentStatusOptions: [
        { value: 1, label: "在线" },
        // { value: 2, label: "使用中" },
        { value: 3, label: "故障" },
        { value: 4, label: "离线" },
      ],
      isFlagOptions: [
        { value: 1, label: "启用" },
        // { value: 2, label: "使用中" },
        { value: 2, label: "禁用" },
      ],
      waterStatusOptions: [
        { value: 1, label: "正常" },
        { value: 2, label: "故障" },
      ],
      smokeStatusOptions: [
        { value: 1, label: "正常" },
        { value: 2, label: "故障" },
      ],
      list: null,
      chargeRules: [],
      downloadLoading: false,
      equipmentCount: 0,
      showPic: "",
      dialogVisible: false,
    };
  },

  methods: {
    async equipmentOtherCmd(equipmentId, deviceId, equipmentNumber,equipmentType) {
      const data = await cmd({
        deviceId: deviceId,
      });
      if (data.code == 1) {
        this.getEquipmentOtherData(equipmentId, deviceId, equipmentNumber,equipmentType);
        this.$message({
          type: "success",
          message: "操作成功",
        });
      } else {
        this.$message({
          type: "error",
          message: data.msg,
        });
      }
    },

    getDateTime(value) {
      console.log(value);
      if (value) {
        this.listQuery.startTime = value[0];
        this.listQuery.endTime = value[1];
      } else {
        this.listQuery.startTime = "";
        this.listQuery.endTime = "";
      }
      console.log(this.listQuery.startTime, "111", this.listQuery.endTime);
    },
    // 获取设备状态
    getEquipmentOtherData(
      equipmentId,
      deviceId,
      equipmentNumber,
      equipmentType
    ) {
      console.log(equipmentId,
      deviceId,
      equipmentNumber,
      equipmentType);
      getEquipmentOtherData({ equipmentId: equipmentId }).then((res) => {
        if (res.code == 1 && res.data) {
          this.equipmentOtherData.equipmentId = equipmentId;
          this.equipmentOtherData.deviceId = deviceId;
          this.equipmentOtherData.equipmentNumber = equipmentNumber;
          this.equipmentOtherData.smokeStatus = res.data.smokeStatus;
          this.equipmentOtherData.waterSensorStatus =
            res.data.waterSensorStatus;
          this.equipmentOtherData.waterTankStatus = res.data.waterTankStatus;
          this.equipmentOtherData.cellVoltage = res.data.cellVoltage;
          this.equipmentOtherData.fireArea = res.data.fireArea; //火灾区域
          this.equipmentOtherData.fireSign = res.data.fireSign; //火灾标志
          this.equipmentOtherData.microSwitch = res.data.microSwitch; //微动开关
          this.equipmentOtherData.levelWarning = res.data.levelWarning; //液位警告
          this.equipmentOtherData.selfCheckStatus = res.data.selfCheckStatus; //自检灯状态
          this.equipmentOtherData.emergencySwitch = res.data.emergencySwitch; //应急开关
          this.equipmentOtherData.list = res.data.list;
          this.equipmentOtherData.equipmentType = equipmentType;
        }
        this.showStatus = true;
      });
    },
    changeChargeLowEbAmount(value) {
      // console.log(value);
      // console.log(this.powerForm);
    },
    // 代理商选择
    chooseAgent(id) {
      // console.log(id);
      this.addQuery.managerId = id;
    },
    //查看二维码
    viewImgList(imgs) {
      this.dialog.view = true;
      // console.log("图片-", imgs);
      imgs = imgs || "";
      this.imgList = imgs.split(",");
    },
    // 展示二维码图片
    onShowPic(img) {
      this.showPic = img;
      this.di;
      alogVisible = true;
    },
    //导出
    handleDownload() {
      this.downloadLoading = true;
      import("@/vendor/Export2Excel").then((excel) => {
        const tHeader = [
          "序号",
          "设备编号",
          "deviceId",
          "鉴权信息",
          "设备类型",
          "设备状态",
          "喇叭状态",
          "地址",
          "省级全资子公司",
          "物业",

          "设备月租(元)",
          "状态",
          "创建时间",
        ];
        const filterVal = [
          "index",
          "equipmentNumber",
          "deviceId",
          "authInfo",
          "equipmentTypeInfo",
          "equipmentStatusInfo",
          "trumpetInfo",
          "address",
          "coUserName",
          "esUserName",
          "monthlyRentInfo",
          "isFlagInfo",
          "ctime",
        ];
        const data = this.formatJson(filterVal, this.list);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: "设备列表",
        });
        this.downloadLoading = false;
      });
    },

    formatJson(filterVal, jsonData) {
      return jsonData.map((v) =>
        filterVal.map((j) => {
          return v[j];
        })
      );
    },
    //文件下载
    async exlDownload() {
      try {
        //调用服务器接口
        const { data } = await downLoadExcel();
        if (data.code == 1) {
          consolse.log(data);
        }
        this.exlDownloadLoading = true;

        setTimeout(() => {
          this.exlDownloadLoading = false;
        }, 1500);
      } catch (err) {}
    },
    //文件导入
    async importEquipments(e) {
      try {
        this.updataLoading = true;
        this.updataTip = "上传中,请稍后...";
        let formData = new FormData();
        const excel = e.target.files[0];

        formData.append("file", excel);
        let file = e.target.files[0];
        let name = e.target.files[0].name;
        //调用服务器接口
        const res = await addEquipmentExcel(formData);

        if (res.code == 1) {
          this.$message({
            type: "success",
            message: "正在新增设备，请稍后刷新...!",
          });

          setTimeout(() => {
            location.reload();
          }, 5000);
        } else if (res.code == 24) {
          this.updataTip = "批量新增";
        } else {
          this.updataTip = "批量新增";
          this.$message({
            type: "error",
            message: res.msg,
          });
        }
        e.target.value = "";
      } catch (err) {
        this.updataTip = "批量新增";
        setTimeout(() => {
          location.reload();
        }, 2000);
        e.target.value = "";
      }
    },
    // 获取设备列表
    async getEquipmentLists() {
      this.loading.list = true;
      try {
        //调用服务器接口
        const { data } = await getEquipmentList({
          ...this.listQuery,
        });

        this.list = data.records.map((item, index) => ({
          index: index + 1,
          equipmentTypeInfo:
            item.equipmentType == 1
              ? "交流"
              : item.equipmentType == 2
              ? "交直流-单模块"
              : item.equipmentType == 3
              ? "交直流-双模块"
              : item.equipmentType == 3
              ? "充电柜"
              : "-",
          address:
            item.province + item.city + item.area + item.equipmentAddress,
          monthlyRentInfo: item.estateId ? item.monthlyRent / 100 : "-",
          trumpetInfo: item.trumpet == 0 ? "打开" : "关闭",
          equipmentStatusInfo:
            item.equipmentStatus == 1
              ? "在线"
              : item.equipmentStatus == 2
              ? "使用中"
              : item.equipmentStatus == 3
              ? "故障"
              : "离线",
          isFlagInfo:
            item.isFlag == 1 ? "启用" : item.isFlag == 2 ? "禁用" : "-",
          ...item,
        }));
        this.total = data.total;
      } catch (error) {}
      this.loading.list = false;
    },

    //获取默认列表
    getLocalTime(now) {
      let date = new Date(now);
      let D = date.getDate() + " ";
      let h = date.getHours() < 9 ? "0" + date.getHours() : date.getHours();
      let m =
        date.getMinutes() < 9 ? "0" + date.getMinutes() : date.getMinutes();
      let s = date.getSeconds();
      return h + ":" + m;
    },
    //查询有无默认套餐
    // 获取系统参数
    async getDefaultMeal() {
      try {
        const { data } = await getSystemParamter(8);
        if (data.parameter == null) {
          this.mealDetail = {
            chargeType: 2,
            chargeAmount: 0,
            chargePowerData: this.defaultChargePowerData,
            serviceData: this.serviceData,
            serviceType: 0,
            serviceAmount: 0,
            servicePeakAmount: 0,
            serviceLowEbAmount: 0,
            custodyType: 0,
            custodyAmount: 0,
            custodyPeakAmount: 0,
            custodyLowEbAmount: 0,
            amountTime: 240,
            serviceTime: 240,
            lowAmount: 1,
            tallAmount: 5,
            peakStartTime: "00:00",
            peakEndTime: "00:00",
            lowEbStartTime: "00:00",
            lowEbEndTime: "00:00",
          };
        } else {
          this.mealDetail = JSON.parse(data.parameter);
          console.log(this.mealDetail);
          this.mealDetail.chargePowerData =
            this.mealDetail.chargePowerData == null
              ? this.defaultChargePowerData
              : JSON.parse(this.mealDetail.chargePowerData);
          this.mealDetail.serviceData =
            this.mealDetail.serviceData == null
              ? this.serviceData
              : JSON.parse(this.mealDetail.serviceData);
          this.mealDetail.peakStartTime =
            this.mealDetail.peakStartTime == null
              ? "00:00"
              : this.getLocalTime(this.mealDetail.peakStartTime);
          this.mealDetail.peakEndTime =
            this.mealDetail.peakEndTime == null
              ? "00:00"
              : this.getLocalTime(this.mealDetail.peakEndTime);

          this.mealDetail.lowEbStartTime =
            this.mealDetail.lowEbStartTime == null
              ? "00:00"
              : this.getLocalTime(this.mealDetail.lowEbStartTime);
          this.mealDetail.lowEbEndTime == null
            ? "00:00"
            : this.getLocalTime(this.mealDetail.lowEbEndTime);
          this.mealDetail.chargeAmount =
            this.mealDetail.chargeAmount == null
              ? 0
              : this.mealDetail.chargeAmount / 100;

          (this.mealDetail.serviceAmount =
            this.mealDetail.serviceAmount == null
              ? 0
              : this.mealDetail.serviceAmount / 100),
            (this.mealDetail.servicePeakAmount =
              this.mealDetail.servicePeakAmount == null
                ? 0
                : this.mealDetail.servicePeakAmount / 100);
          this.mealDetail.serviceLowEbAmount =
            this.mealDetail.serviceLowEbAmount == null
              ? 0
              : this.mealDetail.serviceLowEbAmount / 100;

          this.mealDetail.custodyAmount =
            this.mealDetail.custodyAmount == null
              ? 0
              : this.mealDetail.custodyAmount / 100;
          this.mealDetail.custodyPeakAmount =
            this.mealDetail.custodyPeakAmount == null
              ? 0
              : this.mealDetail.custodyPeakAmount / 100;
          this.mealDetail.custodyLowEbAmount =
            this.mealDetail.custodyLowEbAmount == null
              ? 0
              : this.mealDetail.custodyLowEbAmount / 100;
          this.mealDetail.amountTime =
            this.mealDetail.amountTime == null
              ? 240
              : this.mealDetail.amountTime;
          this.mealDetail.serviceTime =
            this.mealDetail.serviceTime == null
              ? 240
              : this.mealDetail.serviceTime;
          this.mealDetail.lowAmount =
            this.mealDetail.lowAmount == null
              ? ""
              : this.mealDetail.lowAmount / 100;
          this.mealDetail.tallAmount =
            this.mealDetail.tallAmount == null
              ? ""
              : this.mealDetail.tallAmount / 100;
        }
        // console.log("3");
      } catch (err) {
        // console.log(err);
      }
    },

    async getAgentBox(agentType, province) {
      //调用服务器接口
      const { data } = await getBackAgentBox({
        agentType: agentType,
        province: province,
      });
      // console.log("省===", data);
      if (agentType == 1) {
        this.companyList = data;
        var flag = false;
        if (data != "") {
          for (var item in data) {
            if (this.addQuery.companyId == data[item].agentId) {
              flag = true;
              return;
            }
          }
        }
        if (!flag) {
          this.addQuery.companyId = "";
        }
      }
    },
    //添加设备
    async add() {
      this.$refs["bindForm"].validate(async (valid) => {
        if (valid) {
          try {
            this.loading.add = true;
            let query = {
              deviceId: this.addQuery.deviceId,
              equipmentNumber: this.addQuery.equipmentNumber,
              equipmentId: this.addQuery.equipmentId,
              equipmentType: this.addQuery.equipmentType,
              province: getAddress(this.addQuery.province),
              city: getAddress(this.addQuery.city),
              area: getAddress(this.addQuery.area),
              equipmentAddress: this.addQuery.equipmentAddress,
              // companyId: this.addQuery.companyId,
              managerId: this.addQuery.managerId,
            };
            this.loading.add = true;
            if (this.dialogType === 1) {
              //调用服务器接口
              const { data } = await addtem(query);
            } else {
              //调用服务器接口
              const { data } = await updateItem(query);
            }
            this.$message({
              type: "success",
              message: "添加成功",
            });
            this.dialog.add = false;
            this.loading.add = false;
            this.resetForm("bindForm");
            this.getEquipmentLists();
          } catch (error) {
            this.loading.add = false;
            this.resetForm("bindForm");
          }
        } else {
          return false;
        }
      });
    },
    // 添加/修改套餐
    async crateMeal() {
      this.$refs["mealForm"].validate(async (valid) => {
        if (valid) {
          try {
            this.loading.Create = true;
            let query = {
              mealId: this.mealDetail.mealId,
              equipmentId: this.mealDetail.equipmentId,
              chargeType: this.mealDetail.chargeType
                ? this.mealDetail.chargeType
                : 1,
              chargeAmount: parseFloat(
                (this.mealDetail.chargeAmount * 100).toFixed(2)
              ),
              chargePowerData: this.mealDetail.chargePowerData
                ? JSON.stringify(this.mealDetail.chargePowerData)
                : [],
              // 新增两个参数 2024.12.31
              serviceData: this.mealDetail.serviceData
                ? JSON.stringify(this.mealDetail.serviceData)
                : [],
              serviceTime: this.mealDetail.serviceTime
                ? this.mealDetail.serviceTime
                : 60,
              serviceType: this.mealDetail.serviceType
                ? this.mealDetail.serviceType
                : 0,
              serviceAmount: parseFloat(
                (this.mealDetail.serviceAmount * 100).toFixed(2)
              ),
              servicePeakAmount: parseFloat(
                (this.mealDetail.servicePeakAmount * 100).toFixed(2)
              ),
              serviceLowEbAmount: parseFloat(
                (this.mealDetail.serviceLowEbAmount * 100).toFixed(2)
              ),

              custodyType: this.mealDetail.custodyType
                ? this.mealDetail.custodyType
                : 0,
              custodyAmount: parseFloat(
                (this.mealDetail.custodyAmount * 100).toFixed(2)
              ),
              custodyPeakAmount: parseFloat(
                (this.mealDetail.custodyPeakAmount * 100).toFixed(2)
              ),
              custodyLowEbAmount: parseFloat(
                (this.mealDetail.custodyLowEbAmount * 100).toFixed(2)
              ),

              peakStartTime: this.mealDetail.peakStartTime
                ? this.mealDetail.peakStartTime
                : null,
              peakEndTime: this.mealDetail.peakEndTime
                ? this.mealDetail.peakEndTime
                : null,
              lowEbStartTime: this.mealDetail.peakEndTime
                ? this.mealDetail.peakEndTime
                : null,
              lowEbEndTime: this.mealDetail.peakStartTime
                ? this.mealDetail.peakStartTime
                : null,

              amountTime: this.mealDetail.amountTime
                ? this.mealDetail.amountTime
                : 60,

              lowAmount: parseFloat(
                (this.mealDetail.lowAmount * 100).toFixed(2)
              ),
              tallAmount: parseFloat(
                (this.mealDetail.tallAmount * 100).toFixed(2)
              ),
            };
            if (this.isCrate == 1) {
              //调用服务器接口
              const data = await updateEquipmentExcel(query);

              if (data.code == 1) {
                this.$message({
                  type: "success",
                  message: "更新成功",
                });
                this.resetForm("powerForm");
                this.resetForm("powerForm");
              }
              this.resetForm("mealForm");
              this.resetForm("powerForm");
            } else if (this.isCrate == 2) {
              //调用服务器接口
              const data = await addEquipmentMeal(query);
              // console.log("添加成功");
              if (data.code == 1) {
                this.$message({
                  type: "success",
                  message: "添加成功",
                });
              }
              this.resetForm("mealForm");
              this.resetForm("powerForm");
            }
            this.dialog.create = false;
            this.loading.create = false;
            this.getEquipmentLists();
          } catch (error) {
            this.loading.create = false;
            this.dialog.create = false;
            this.resetForm("mealForm");
            this.resetForm("powerForm");
          }
        }
      });
    },
    // table取消选择
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    //批量选择显示
    selectionShow(e) {
      this.selectionView = true;
      this.toggleSelection();
      if (e === 1) {
        // 设备套餐
        this.equipmentIdsType = 1;
      } else if (e == 2) {
        // 设备卡套餐
        this.equipmentIdsType = 2;
      }
    },
    //批量选择
    handleSelectionChange(e) {
      this.selectionArray = e;
    },
    // 拼接设备id
    getEquipmentIds() {
      this.mealDetail = {
        mealId: null,
        equipmentId: null,
        chargeType: 1,
        chargeAmount: 0,
        chargePeakAmount: 0,
        chargeLowEbAmount: 0,
        serviceType: 0,
        serviceAmount: 0,
        servicePeakAmount: 0,
        serviceLowEbAmount: 0,
        custodyType: 0,
        custodyAmount: 0,
        custodyPeakAmount: 0,
        custodyLowEbAmount: 0,
        amountTime: 60,
        serviceTime: 60,
        lowAmount: 0,
        tallAmount: 0,
        peakStartTime: "00:00",
        peakEndTime: "00:00",
        lowEbStartTime: "00:00",
        lowEbEndTime: "00:00",
        chargePowerData: [
          {
            chargeLowEbAmount: 100,
            chargePeakAmount: 200,
            spower: 0,
            epower: 150,
          },
          {
            chargeLowEbAmount: 200,
            chargePeakAmount: 300,
            spower: 150,
            epower: 200,
          },
          {
            chargePeakAmount: 300,
            chargeLowEbAmount: 400,
            spower: 200,
            epower: 250,
          },
          {
            chargeLowEbAmount: 400,
            chargePeakAmount: 500,
            spower: 250,
            epower: 300,
          },
          {
            chargeLowEbAmount: 500,
            chargePeakAmount: 600,
            spower: 300,
            epower: 350,
          },
          {
            chargeLowEbAmount: 600,
            chargePeakAmount: 700,
            spower: 350,
            epower: 400,
          },
          {
            chargeLowEbAmount: 700,
            chargePeakAmount: 800,
            spower: 400,
            epower: 450,
          },
        ],
        // 功率服务费表
        serviceData: [
        {
          chargePeakAmount: 100,
          spower: 0,
          epower: 150,
        },
        {
          chargePeakAmount: 200,
          spower: 150,
          epower: 200,
        },
        {
          chargePeakAmount: 300,
          spower: 200,
          epower: 250,
        },
        {
          chargePeakAmount: 400,
          spower: 250,
          epower: 300,
        },
        {
          chargePeakAmount: 500,
          spower: 300,
          epower: 350,
        },
        {
          chargePeakAmount: 600,
          spower: 350,
          epower: 400,
        },
        {
          chargePeakAmount: 700,
          spower: 400,
          epower: 450,
        },
      ],
      };
      if (this.selectionArray.length > 0) {
        for (var i = 0; i < this.selectionArray.length; i++) {
          this.equipmentIds =
            this.equipmentIds == null
              ? (this.equipmentIds = this.selectionArray[0].equipmentId)
              : this.equipmentIds + "," + this.selectionArray[i].equipmentId;
        }
        if (this.equipmentIdsType == 1) {
          this.dialog.create = true;
        } else if (this.equipmentIdsType == 2) {
          this.dialog.addEquipmentCard = true;
        }
      } else {
        this.$message({
          type: "error",
          message: "请选择需要设置套餐的设备",
        });
      }
    },

    // 批量更新设备套餐
    async addOrUpdateList() {
      this.$refs["mealForm"].validate(async (valid) => {
        if (valid) {
          try {
            this.loading.Create = true;
            let query = {
              mealId: this.mealDetail.mealId,
              equipmentIds: this.equipmentIds,
              chargeType: this.mealDetail.chargeType
                ? this.mealDetail.chargeType
                : 1,
              chargeAmount:
                this.mealDetail.chargeAmount * 100
                  ? this.mealDetail.chargeAmount * 100
                  : 0,
              chargePowerData: this.mealDetail.chargePowerData
                ? JSON.stringify(this.mealDetail.chargePowerData)
                : [],
              // 新增两个参数 2024.12.31
              serviceData: this.mealDetail.serviceData
                ? JSON.stringify(this.mealDetail.serviceData)
                : [],
              serviceTime: this.mealDetail.serviceTime
                ? this.mealDetail.serviceTime
                : 60,
              serviceType: this.mealDetail.serviceType
                ? this.mealDetail.serviceType
                : 0,
              serviceAmount:
                this.mealDetail.serviceAmount * 100
                  ? this.mealDetail.serviceAmount * 100
                  : 0,
              servicePeakAmount:
                this.mealDetail.servicePeakAmount * 100
                  ? this.mealDetail.servicePeakAmount * 100
                  : 0,
              serviceLowEbAmount:
                this.mealDetail.serviceLowEbAmount * 100
                  ? this.mealDetail.serviceLowEbAmount * 100
                  : 0,

              custodyType: this.mealDetail.custodyType
                ? this.mealDetail.custodyType
                : 0,
              custodyAmount:
                this.mealDetail.custodyAmount * 100
                  ? this.mealDetail.custodyAmount * 100
                  : 0,
              custodyPeakAmount:
                this.mealDetail.custodyPeakAmount * 100
                  ? this.mealDetail.custodyPeakAmount * 100
                  : 0,
              custodyLowEbAmount:
                this.mealDetail.custodyLowEbAmount * 100
                  ? this.mealDetail.custodyLowEbAmount * 100
                  : 0,
              peakStartTime: this.mealDetail.peakStartTime
                ? this.mealDetail.peakStartTime
                : null,
              peakEndTime: this.mealDetail.peakEndTime
                ? this.mealDetail.peakEndTime
                : null,
              lowEbStartTime: this.mealDetail.peakEndTime
                ? this.mealDetail.peakEndTime
                : null,
              lowEbEndTime: this.mealDetail.peakStartTime
                ? this.mealDetail.peakStartTime
                : null,

              amountTime: this.mealDetail.amountTime
                ? this.mealDetail.amountTime
                : 60,

              lowAmount:
                this.mealDetail.lowAmount * 100
                  ? this.mealDetail.lowAmount * 100
                  : 0,
              tallAmount:
                this.mealDetail.tallAmount * 100
                  ? this.mealDetail.tallAmount * 100
                  : 0,
            };
            const { data } = await addOrUpdateList(query);

            this.$message({
              type: "success",
              message: "批量修改中，请稍后刷新",
            });

            setTimeout(() => {
              this.dialog.create = false;
              this.loading.create = false;
              this.selectionView = false;
              this.equipmentIds = null;
              this.resetForm("mealForm");
              this.resetForm("powerForm");
              location.reload();
            }, 1500);
            // this.getEquipmentLists();
          } catch (error) {
            this.$message({
              type: "error",
              message: "批量修改失败，请联系后台",
            });

            setTimeout(() => {
              this.selectionView = false;
              this.equipmentIds = null;
              this.loading.create = false;
              this.dialog.create = false;
              this.resetForm("mealForm");
              this.resetForm("powerForm");
            }, 1500);
          }
        }
      });
    },
    // 批量新增设备卡套餐
    addEquipmentCardList() {
      try {
        this.$refs["EquipmentCardRules"].validate(async (valid) => {
          if (valid) {
            //调用服务器接口
            const { data } = await addCardTypeList({
              equipmentIds: this.equipmentIds,
              timeDay: this.EquipmentCardinfo.timeDay,
              useTimeQuantum: this.EquipmentCardinfo.useTimeQuantum * 3600000,
              amount: this.EquipmentCardinfo.amount * 100,
            });
            this.dialog.addEquipmentCard = false;
            this.$message({
              type: "success",
              message: "批量修改中，请稍后刷新...",
            });
            setTimeout(() => {
              this.selectionView = false;
              this.equipmentIds = null;
              this.resetForm("EquipmentCardForm");
              location.reload();
            }, 2000);
          }
        });
      } catch (err) {
        setTimeout(() => {
          this.selectionView = false;
          this.equipmentIds = null;
          this.resetForm("EquipmentCardForm");
          location.reload();
        }, 2000);
      }
      // });
    },

    //喇叭命令
    updateTrumpet(deviceId, trumpetCode) {
      let type;
      if (trumpetCode) {
        type = trumpetCode == "00" ? "打开喇叭命令" : "关闭喇叭命令";
      }
      this.$confirm(`是否发送${type}?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          //调用服务器接口
          const { data } = await updateTrumpet({
            deviceId: deviceId,
            trumpet: trumpetCode,
          });
          this.$message({
            type: "success",
            message: `${type}发送成功!`,
          });
          this.getEquipmentLists();
        })
        .catch(() => {});
    },

    //更新设备状态
    getOneNetData(deviceId, trumpetCode) {
      this.$confirm(`是否更新设备状态?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          //调用服务器接口
          const { data } = await getOneNetData({
            deviceId: deviceId,
          });
          this.$message({
            type: "success",
            message: `更新成功!`,
          });
          this.getEquipmentLists();
        })
        .catch(() => {});
    },
    // 套餐转成数组格式
    packageSwitching(dataString){
      // 1. 去掉外层的方括号
      const trimmedString = dataString.slice(1, -1);
      // 2. 按对象拆分字符串
      const objectStrings = trimmedString.split('), ');
      // 3. 提取对象的属性并构建对象数组
      const result = objectStrings.map(str => {
          // 去掉 ChargePowerData( 和末尾的 )
          const cleanedStr = str.replace('ChargePowerData(', '').replace(')', '');
          // 将属性字符串拆分为键值对
          const keyValuePairs = cleanedStr.split(', ');
          // 构建对象
          const obj = {};
          keyValuePairs.forEach(pair => {
              const [key, value] = pair.split('=');
              obj[key] = parseFloat(value); // 将值转换为数字
          });
          return obj;
      });
      return result 
    },
    // 套餐
    async mealView(id) {
      // console.log("111");
      this.dialog.create = true;
      this.mealDetail.equipmentId = id;
      //调用服务器接口
      const data = await getEquipmentMeal({ equipmentId: id });
      console.log(data);

      if (data.data != null) {
        this.$message({
          type: "success",
          message: "已有套餐,可更新",
        });
        this.mealDetail = data.data;
        this.mealDetail.chargePowerData =
          data.data.chargePowerData == null
            ? []
            : JSON.parse(data.data.chargePowerData);
        this.mealDetail.serviceData =
          data.data.serviceData == null
            ? []
            : JSON.parse(data.data.serviceData)
        this.mealDetail.mealId = data.data.mealId;

        this.mealDetail.peakStartTime =
          data.data.peakStartTime == null
            ? "00:00"
            : data.data.peakStartTime.slice(11, 16);
        this.mealDetail.peakEndTime =
          data.data.peakEndTime == null
            ? "00:00"
            : this.mealDetail.peakEndTime.slice(11, 16);
        this.mealDetail.lowEbStartTime =
          data.data.lowEbStartTime == null ? "00:00" : data.data.lowEbStartTime;
        this.mealDetail.lowEbEndTime =
          data.data.lowEbEndTime == null ? "00:00" : data.data.lowEbEndTime;
        this.mealDetail.chargeAmount =
          data.data.chargeAmount == null ? 0 : data.data.chargeAmount / 100;
        this.mealDetail.serviceAmount =
          data.data.serviceAmount == null ? 0 : data.data.serviceAmount / 100;
        this.mealDetail.servicePeakAmount =
          data.data.servicePeakAmount == null
            ? 0
            : data.data.servicePeakAmount / 100;
        this.mealDetail.serviceLowEbAmount =
          data.data.serviceLowEbAmount == null
            ? 0
            : data.data.serviceLowEbAmount / 100;
        this.mealDetail.custodyAmount =
          data.data.custodyAmount == null ? 0 : data.data.custodyAmount / 100;
        this.mealDetail.custodyPeakAmount =
          data.data.custodyPeakAmount == null
            ? 0
            : data.data.custodyPeakAmount / 100;
        this.mealDetail.custodyLowEbAmount =
          data.data.custodyLowEbAmount == null
            ? 0
            : data.data.custodyLowEbAmount / 100;
        this.mealDetail.amountTime =
          data.data.amountTime == null ? 60 : data.data.amountTime;
        this.mealDetail.serviceTime =
          data.data.serviceTime == null ? 60 : data.data.serviceTime;
        this.mealDetail.lowAmount =
          data.data.lowAmount == null ? "" : data.data.lowAmount / 100;
        this.mealDetail.tallAmount =
          data.data.tallAmount == null ? "" : data.data.tallAmount / 100;
        this.isCrate = 1;
      } else {
        this.mealDetail = {
          equipmentId: id,
          chargeType: 1,
          chargeAmount: 0,
          chargePowerData: this.defaultChargePowerData,
          serviceData: this.serviceData,
          serviceType: 0,
          serviceAmount: 0,
          servicePeakAmount: 0,
          serviceLowEbAmount: 0,
          custodyType: 0,
          custodyAmount: 0,
          custodyPeakAmount: 0,
          custodyLowEbAmount: 0,
          amountTime: 60,
          serviceTime: 60,
          lowAmount: 0,
          tallAmount: 0,
          peakStartTime: "00:00",
          peakEndTime: "00:00",
          lowEbStartTime: "00:00",
          lowEbEndTime: "00:00",
        },
        //   this.isCrate = 2;
        // this.$message({
        //   type: "warning",
        //   message: "暂无套餐，请添加",
        // });
        await this.getDefaultMeal();
        this.mealDetail.equipmentId = id;
        console.log(this.mealDetail);
        this.isCrate = 2;
        this.$message({
          type: "warning",
          message: "暂无套餐，请添加",
        });
      }
    },
    // 套餐
    changeChargeMealVisible(item, index) {
      this.powerFormVisible = true;
      // console.log("选择套餐时", this.powerForm);
      if (item) {
        /**
         * 2022.08.15  唐
         * log:变更无法修改套餐高峰低谷间隔问题
         * */
        // this.powerForms = {};

        for (let j = 0; j < this.mealDetail.chargePowerData.length; j++) {
          this.powerSizeClass[j] = "powerSize";
          if (j == index) {
            this.powerSizeClass[j] = "powerSizeSel";
          }
        }
        this.powerFormList.chargePeakAmount = this.divide(item.chargePeakAmount,100);
        this.powerFormList.chargeLowEbAmount = this.divide(item.chargeLowEbAmount,100);
        this.powerFormList.spower = item.spower;
        this.powerFormList.epower = item.epower;
        this.powerFormList.index = index;

        // this.powerForms = this.powerFormList;

        this.powerForms.chargePeakAmount = this.divide(item.chargePeakAmount,100);
        this.powerForms.chargeLowEbAmount = this.divide(item.chargeLowEbAmount,100);
        this.powerForms.spower = item.spower;
        this.powerForms.epower = item.epower;
        this.powerForms.index = index;
        // console.log(this.mealDetail.chargePowerData.length - 1, index);
        if (index == this.mealDetail.chargePowerData.length - 1) {
          this.powerForms.disabledSpower = true;
          this.powerForms.disabledEpower = false;
        } else if (index < this.mealDetail.chargePowerData.length) {
          this.powerForms.disabledSpower = true;
          this.powerForms.disabledEpower = true;
        }
      } else {
        // 新增
        // console.log("changeChargeMealVisible2");
        this.powerFormList = {};
        this.powerForms = {};
        // 衔接上一个功率段
        this.powerForms.spower =
          this.mealDetail.chargePowerData[
            this.mealDetail.chargePowerData.length - 1
          ].epower;
        this.powerForms.disabledSpower = true;
      }
    },
    // 服务费套餐
    changeChargeMealVis2(item, index) {
      this.powerFormVisible = true;
      // console.log("选择套餐时", this.powerForm);
      if (item) {

        for (let j = 0; j < this.mealDetail.serviceData.length; j++) {
          this.powerSizeClass[j] = "powerSize";
          if (j == index) {
            this.powerSizeClass[j] = "powerSizeSel";
          }
        }
        this.powerFormList.chargePeakAmount = item.chargePeakAmount / 100;
        this.powerFormList.spower = item.spower;
        this.powerFormList.epower = item.epower;
        this.powerFormList.index = index;

        // this.powerForms = this.powerFormList;

        this.powerForms.chargePeakAmount = item.chargePeakAmount / 100;
        this.powerForms.spower = item.spower;
        this.powerForms.epower = item.epower;
        this.powerForms.index = index;
        // console.log(this.mealDetail.serviceData.length - 1, index);
        if (index == this.mealDetail.serviceData.length - 1) {
          this.powerForms.disabledSpower = true;  
          this.powerForms.disabledEpower = false;
        } else if (index < this.mealDetail.serviceData.length) {
          this.powerForms.disabledSpower = true;
          this.powerForms.disabledEpower = true;
        }
      } else {
        // 新增
        // console.log("changeChargeMealVisible2");
        this.powerFormList = {};
        this.powerForms = {};
        // 衔接上一个功率段
        this.powerForms.spower =
          this.mealDetail.serviceData[
            this.mealDetail.serviceData.length - 1
          ].epower;
        this.powerForms.disabledSpower = true;
      }
    },
    changeChargeMeal() {
      this.$refs["powerForm"].validate((valid) => {
        if (valid) {
          // console.log(valid);
          // 修改
          if (this.powerFormList.chargePeakAmount > 0) {
            let index = this.powerFormList.index;
            let item = this.powerFormList.item;
            for (let i = 0; i < this.mealDetail.chargePowerData.length; i++) {
              if (i == index) {
                this.mealDetail.chargePowerData[i].chargePeakAmount =
                this.multiply(this.powerForms.chargePeakAmount,100)
                  // this.powerForms.chargePeakAmount * 100;
                this.mealDetail.chargePowerData[i].chargeLowEbAmount =
                this.multiply(this.powerForms.chargeLowEbAmount,100)
                this.mealDetail.chargePowerData[i].spower =
                  this.powerForms.spower;
                this.mealDetail.chargePowerData[i].epower =
                  this.powerForms.epower;
              }
            }
            this.powerFormVisible = false;
          } else {
            // 新增
            this.mealDetail.chargePowerData.push({
              chargePeakAmount: this.multiply(this.powerForms.chargePeakAmount,100),
              chargeLowEbAmount: this.multiply(this.powerForms.chargeLowEbAmount,100),
              spower: this.powerForms.spower,
              epower: this.powerForms.epower,
            });
          }
          this.concelpowerSizeClass();
          // 发请求改设备设置
          this.powerFormVisible = false;
        }
      });
    },
    cancelChangeChargeMeal() {
      this.powerFormVisible = false;
      this.concelpowerSizeClass();
    },

    // 取消样式
    concelpowerSizeClass() {
      for (let j = 0; j < this.mealDetail.chargePowerData.length; j++) {
        this.powerSizeClass[j] = "powerSize";
      }
    },
    // 删除功率段
    delPowerSize() {
      this.cancelChangeChargeMeal();
      this.powerForms = {
        chargePeakAmount: "",
        chargeLowEbAmount: "",
        spower: "",
        epower: "",
        disabledSpower: false,
        disabledEpower: false,
      };

      // console.log(
      //   this.mealDetail.chargePowerData.length - 1,
      //   this.mealDetail.chargePowerData.length - 2
      // );
      if (this.mealDetail.chargePowerData.length > 2) {
        this.mealDetail.chargePowerData.length =
          this.mealDetail.chargePowerData.splice(
            this.mealDetail.chargePowerData.length - 1,
            this.mealDetail.chargePowerData.length - 2
          );
      } else if (this.mealDetail.chargePowerData.length == 2) {
        this.mealDetail.chargePowerData =
          this.mealDetail.chargePowerData.splice(0, 1);
      } else if (this.mealDetail.chargePowerData.length == 1) {
        this.mealDetail.chargePowerData = [];
      }
    },
    // 判断数字有没有超过两位小数
    hasMoreThanTwoDecimals(num) {
      let strNum = num.toString();
      let decimalIndex = strNum.indexOf('.');
      if (decimalIndex === -1) {
        return false;
      }
      let decimalPart = strNum.slice(decimalIndex + 1);
      return decimalPart.length > 2;
    },
    changeChargeMeal2() {
      this.$refs["powerForm"].validate((valid) => {
        console.log(this.powerForms.chargePeakAmount)
        if(this.hasMoreThanTwoDecimals(this.powerForms.chargePeakAmount)) return this.$message.warning('价格只能保留两位小数！')
        if (valid) {
          // 修改
          if (this.powerFormList.chargePeakAmount > 0) {
            let index = this.powerFormList.index;
            let item = this.powerFormList.item;
            for (let i = 0; i < this.mealDetail.serviceData.length; i++) {
              if (i == index) {
                this.mealDetail.serviceData[i].chargePeakAmount =
                  this.powerForms.chargePeakAmount * 100
                this.mealDetail.serviceData[i].spower =
                  this.powerForms.spower;
                this.mealDetail.serviceData[i].epower =
                  this.powerForms.epower;
              }
            }
            this.powerFormVisible = false;
          } else {
            // 新增
            this.mealDetail.serviceData.push({
              chargePeakAmount: this.powerForms.chargePeakAmount * 100,
              spower: this.powerForms.spower,
              epower: this.powerForms.epower,
            });
          }
          this.concelpowerSizeClas2();
          // 发请求改设备设置
          this.powerFormVisible = false;
        }
      });
    },
    cancelChangeChargeM2() {
      this.powerFormVisible = false;
      this.concelpowerSizeClas2();
    },

    // 取消样式
    concelpowerSizeClas2() {
      for (let j = 0; j < this.mealDetail.serviceData.length; j++) {
        this.powerSizeClass[j] = "powerSize";
      }
    },
    
    // 删除服务费功率段
    delPowerSize2() {
      this.cancelChangeChargeM2();
      this.powerForms = {   
        chargePeakAmount: "",
        spower: "",
        epower: "",
        disabledSpower: false,
        disabledEpower: false,
      };
      if (this.mealDetail.serviceData.length > 2) {
        this.mealDetail.serviceData.length = 
        this.mealDetail.serviceData.splice(
            this.mealDetail.serviceData.length - 1,
            this.mealDetail.serviceData.length - 2
          );
          console.log(this.mealDetail.serviceData.length)
          console.log(this.mealDetail.serviceData)
      } else if (this.mealDetail.serviceData.length == 2) {
        this.mealDetail.serviceData =
          this.mealDetail.serviceData.splice(0, 1);
      } else if (this.mealDetail.serviceData.length == 1) {
        this.mealDetail.serviceData = [];
      }
    },

    // 表单刷新
    resetForm(formName) {
      if (formName == "bindForm") {
        this.$refs.bindForm && this.$refs.bindForm.resetFields();
      } else if (formName == "mealForm") {
        this.$refs.mealForm && this.$refs.mealForm.resetFields();
      } else if (formName == "powerForm") {
        this.$refs.powerForm && this.$refs.powerForm.resetFields();
      } else if (formName == "EquipmentCardForm") {
        this.$refs.EquipmentCardForm &&
          this.$refs.EquipmentCardForm.resetFields();
      }
    },

    //新增设备套餐
    async EquipmentCardView(status, id, equipmentNumber, area, city, address) {
      this.EquipmentCardinfo.status = status;
      this.EquipmentCardinfo.area = area;
      this.EquipmentCardinfo.city = city;
      this.EquipmentCardinfo.equipmentId = id;
      this.EquipmentCardinfo.equipmentNumber = equipmentNumber;
      this.EquipmentCardinfo.address = area + city + address;
      (this.EquipmentCardinfo.cardType = 2),
        (this.dialog.addEquipmentCard = true);

      if (status == 1) {
        this.$message({
          type: "success",
          message: "已有套餐，可更新",
        });
        //调用服务器接口
        const data = await getEquipmentCardList({
          equipmentId: id,
          offset: 1,
          limit: 1,
          cardType: 2,
        });
        if (data.code == 1) {
          this.EquipmentCardinfo.timeDay = data.data.records[0].timeDay;
          this.EquipmentCardinfo.useTimeQuantum =
            data.data.records[0].useTimeQuantum / 3600000;
          this.EquipmentCardinfo.amount = data.data.records[0].amount / 100;
          this.EquipmentCardinfo.cardTypeId = data.data.records[0].cardTypeId;
        }
      } else {
        this.$message({
          type: "warning",
          message: "暂无套餐，请添加",
        });
        this.EquipmentCardinfo.timeDay = "";
        this.EquipmentCardinfo.amount = "";
        this.EquipmentCardinfo.useTimeQuantum = "";
      }
    },
    addCard() {
      if (this.EquipmentCardinfo.status == 2) {
        //调用服务器接口
        try {
          this.$refs["EquipmentCardForm"].validate(async (valid) => {
            if (valid) {
              const data = await addEquipmentCard({
                ...this.EquipmentCardinfo,
                useTimeQuantum: this.EquipmentCardinfo.useTimeQuantum * 3600000,
                amount: this.EquipmentCardinfo.amount * 100,
              });
              if (data.code == 1) {
                this.dialog.addEquipmentCard = false;
                this.$message({
                  type: "success",
                  message: "新增成功",
                });
                this.getEquipmentLists();
                this.resetForm("EquipmentCardForm");
              }
            }
          });
        } catch (err) {}
      } else if (this.EquipmentCardinfo.status == 1) {
        //调用服务器接口
        try {
          this.$refs["EquipmentCardForm"].validate(async (valid) => {
            if (valid) {
              const data = await updateEquipmentCard({
                ...this.EquipmentCardinfo,
                useTimeQuantum: this.EquipmentCardinfo.useTimeQuantum * 3600000,
                amount: this.EquipmentCardinfo.amount * 100,
              });
              if (data.code == 1) {
                this.dialog.addEquipmentCard = false;
                this.$message({
                  type: "success",
                  message: "更新成功",
                });
                this.getEquipmentLists();
                this.resetForm("EquipmentCardForm");
              }
            }
          });
        } catch (err) {}
      }
    },
    //删除
    detele(equipmentId, deviceId) {
      this.$confirm("是否删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        try {
          //调用服务器接口
          const { data } = await delEquipment({
            equipmentId: equipmentId,
            deviceId: deviceId,
          });
          this.$message({
            type: "success",
            message: "删除成功",
          });
          this.getEquipmentLists();
        } catch (error) {}
      });
    },

    //解绑设备
    unbind(equipmentId) {
      this.$confirm("是否解绑?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        try {
          //调用服务器接口
          const { data } = await unbindBatch({ equipmentId });
          this.$message({
            type: "success",
            message: "解绑成功",
          });
          this.getEquipmentLists();
        } catch (error) {}
      });
    },
    //禁用启用
    updateIsFlag(equipmentId, deviceId, status) {
      let type;
      if (status) {
        type = status == 1 ? "启用" : "禁用";
      } else {
        type = "启用";
      }
      this.$confirm(`确定${type}?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          //调用服务器接口
          const { data } = await updateIsFlag({
            equipmentId: equipmentId,
            deviceId: deviceId,
            isFlag: status,
          });
          this.$message({
            type: "success",
            message: `${type}成功!`,
          });
          this.getEquipmentLists();
        })
        .catch(() => {});
    },
    // 批量下载设备二维码
    downloadZipQr() {
      window.location.href =
        this.$uploadUrl + "api/equipment/admin/downloadZipQr";
    },
    beforOpenDialog(type, item) {
      // console.log(item);
      this.getManagerList();
      if (type === 1) {
        this.resetForm("bindForm");
      } else {
        this.resetForm("bindForm");
        const {
          equipmentId,
          equipmentNumber,
          deviceId,
          equipmentType,
          province,
          city,
          area,
          equipmentAddress,
          companyId,
          authInfo,
          managerId,
        } = item;

        this.addQuery = {
          ...this.addQuery,
          equipmentId,
          equipmentNumber,
          deviceId,
          equipmentType,
          province,
          city,
          area,
          equipmentAddress,
          companyId,
          deviceId,
          managerId,
        };
        this.agentList.map((item) => {
          if (item.managerId == this.addQuery.managerId) {
            this.addQuery.managerId = item.managerId;
          }
        });
        this.addQuery.province = getByNameProvinceId(province);
        this.addQuery.city = getByNameCityId(province, city);
        this.addQuery.area = getByNameAreaId(province, city, area);
        this.getCities2();
        this.getAreas2();
        this.getAgentBox(1, province);
      }

      this.dialogType = type;
      this.dialog.add = true;
    },
    handleFilter() {
      this.listQuery.offset = 1;
      this.getEquipmentLists();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getEquipmentLists();
    },
    handleCurrentChange(val) {
      this.listQuery.offset = val;
      this.getEquipmentLists();
    },
    //根据fid 查询省、市、区  fid = 0 查询所有省；查询市或者地区 fid 传对应的省areaID
    getAddressByAreaId(fid) {
      return getAddressByAreaId(fid);
    },
    // 获取对应市
    getCities2(type) {
      if (type) {
        this.addQuery.city = "";
        this.addQuery.area = "";
      }
      this.pId = this.addQuery.province;
      var pr = "";
      if (this.addQuery.province) {
        pr = getAddress(this.addQuery.province);
      }
      this.getAgentBox(1, pr);
      this.cities = getAddressByAreaId(this.pId);
      // console.log("this.cities====", this.cities);
    },
    // 获取对应的地区
    getAreas2(type) {
      if (type) {
        this.addQuery.area = "";
      }
      this.pId = this.addQuery.city;
      this.areas = getAddressByAreaId(this.pId);
    },
    // 获取对应市Id
    getCities() {
      this.addQuery.area = "";
      this.areas = [];
      this.cities = getAddressByAreaId(this.pId);
    },
    // 获取对应的地区
    getAreas() {
      this.addQuery.area = "";
      this.areas = getAddressByAreaId(this.cId);
    },
    // 获取代理商
    /**
     * auth:
     * date:2022.4.19
     * */
    async getManagerList() {
      let res = await getManagerList();
      this.agentList = [];
      if (res.code == 1) {
        res.data.map((item) => {
          this.agentList.push(item);
        });
      }
    },
  },

  computed: {
    diglogTitle() {
      return this.dialogType === 1 ? "新增设备" : "编辑设备";
    },
  },
  created() {
    console.log('开始',this.multiply(0.5124,100))
    this.getEquipmentLists();
    this.provices = getAddressByAreaId(0);
    // this.getCities();
    // this.getAreas();
  },
  mounted() {},
};
</script>
<style lang="scss" scoped>
.fireSign {
  height: 50px;
  width: 50px;
  border-radius: 50%;
  text-align: center;
  line-height: 50px;
}
.el-button + .el-button {
  margin-left: 0px;
}
.powerSize {
  line-height: 2;
  margin-right: 10px;
  margin-bottom: 10px;
  border-radius: 10px;
  border: 1px solid #dcdfe6;
  text-align: center;
}
.powerSizeSel {
  line-height: 2;
  margin-right: 10px;
  margin-bottom: 10px;
  border-radius: 10px;
  border: 1px solid #4e9aff;
  text-align: center;
}
.powerSizeTop {
  border-bottom: 1px solid #dcdfe6;
}
.powerRates {
  padding: 10px;
  line-height: 2;
  text-align: center;
  border: 1px solid #dcdfe6;
  border-radius: 5px;
}
.powerSizeInp {
  width: 50px;
  height: 50px;
  margin: 5px;
}
.powerSizeTitle {
  display: flex;
  flex-wrap: wrap;
}
</style>
